ArrayAdapter创建ListView学习笔记

activity_main.xml总的布局文件、array_item.xml为list1的布局、checked_item.xml为list2的布局。
java代码:

super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView list1 = (ListView) findViewById(R.id.list1); // 定义一个数组 String[] arr1 = { "孙悟空", "猪八戒", "牛魔王" }; // 将数组包装ArrayAdapter ArrayAdapter adapter1 = new ArrayAdapter (this, R.layout.array_item, arr1); // 为ListView设置Adapter list1.setAdapter(adapter1); ListView list2 = (ListView) findViewById(R.id.list2); // 定义一个数组 String[] arr2 = { "Java", "Hibernate", "Spring" , "Android" }; // 将数组包装ArrayAdapter ArrayAdapter adapter2 = new ArrayAdapter (this, R.layout.checked_item, arr2); // 为ListView设置Adapter list2.setAdapter(adapter2); }


activity_main.xml代码:
【ArrayAdapter创建ListView学习笔记】


array_item.xml代码:



checked_item.xml代码:



显示效果: ArrayAdapter创建ListView学习笔记
文章图片






    推荐阅读