三个Listview使用单个自定义阵列适配器

时间:2012-10-09 10:36:49

标签: android android-layout android-listview android-arrayadapter

我有三个listview,一个模型和自定义数组适配器。我正在尝试为所有三个listview重复使用相同的自定义数组适配器和模型,并且每个listview包含在getview中加载的不同图像集。

有人能给我一个实现它的方法吗?

2 个答案:

答案 0 :(得分:1)

是的,你可以重用你的适配器。就像看到示例代码

一样
customAdapter1 cusad1 = new customAdapter1 (YourActivity1.this,R.layout.row_list,yourlist1);
        list1.setAdapter(customAdapter1);

customAdapter2 cusad2 = new customAdapter2 (YourActivity2.this,R.layout.row_list,yourlist2);
        list2.setAdapter(customAdapter2);

customAdapter3 cusad3 = new customAdapter2 (YourActivity3.this,R.layout.row_list,yourlist3);
        list2.setAdapter(customAdapter3);

答案 1 :(得分:0)

那里没什么难的......

MyArrayAdater myAdapter1= new MyArrayAdater (...myData for list 1....);
MyArrayAdater myAdapter2= new MyArrayAdater (...myData for list 2....);
MyArrayAdater myAdapter3= new MyArrayAdater (...myData for list 3....);

并将每个listView的适配器设置为所需的适配器。