Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用不同的ArrayList多次处理ArrayAdapter类的使用_Java_Android_Arraylist_Android Arrayadapter - Fatal编程技术网

Java 如何使用不同的ArrayList多次处理ArrayAdapter类的使用

Java 如何使用不同的ArrayList多次处理ArrayAdapter类的使用,java,android,arraylist,android-arrayadapter,Java,Android,Arraylist,Android Arrayadapter,如何为4个不同的列表视图使用一个arrayAdapter。我有4个不同的ArrayList,我正在传递到arrayAdapter。而不是复制和粘贴以生成4个ArrayAdapter类,这些类除了输入适配器的arrayList特定的几行之外都是相同的。对4个单独的ArrayList使用相同的arrayAdapter类如何 问题是我需要ArrayAdapter知道输入了4个ArrayList中的哪一个,因为适配器类方法中有一个switch语句 在这种情况下,我是否应该向这个ArrayAdapter类

如何为4个不同的列表视图使用一个arrayAdapter。我有4个不同的ArrayList,我正在传递到arrayAdapter。而不是复制和粘贴以生成4个ArrayAdapter类,这些类除了输入适配器的arrayList特定的几行之外都是相同的。对4个单独的ArrayList使用相同的arrayAdapter类如何

问题是我需要ArrayAdapter知道输入了4个ArrayList中的哪一个,因为适配器类方法中有一个switch语句

在这种情况下,我是否应该向这个ArrayAdapter类的构造函数添加一个额外的参数变量,作为输入四个ArrayList中哪一个的标识符?像int

因为我的适配器类扩展了ArrayAdapter类,我该怎么做?我是否只需在构造函数参数中再添加一个变量位置,然后让超级调用与以前一样,如下所示

super(context, textViewResourceId, objects);
你将如何处理这个问题

  // array adapter where you enter the array
        SelectorListAdapter adapter = new SelectorListAdapter(activity, R.layout.row_layout, smallTank2listInfo1Array);
        SelectorListAdapter adapter2 = new SelectorListAdapter(activity, R.layout.row_layout, smallTank2listInfo2Array);
        SelectorListAdapter adapter3 = new SelectorListAdapter(activity, R.layout.row_layout, smallTank2listInfo3Array);
        SelectorListAdapter adapter4 = new SelectorListAdapter(activity, R.layout.row_layout, smallTank2listInfo4Array);

             // set array adapter to listview
            listViewOne.setAdapter(adapter);
            listViewTwo.setAdapter(adapter2);
            listViewThree.setAdapter(adapter3);
            listViewFour.setAdapter(adapter4);



  public class SelectorListAdapter extends ArrayAdapter<CheckBoxListInfo>{
        ArrayList<CheckBoxListInfo> objects;
        Context context;
        int textViewResourceId;
        private String tempLabel;
        private boolean isChecked;

        public SelectorListAdapter(Context context, int textViewResourceId,
            ArrayList<CheckBoxListInfo> objects) {
            super(context, textViewResourceId, objects);
            this.context = context;
            this.textViewResourceId = textViewResourceId;
            this.objects = objects;

        }
//输入数组的数组适配器
SelectorListAdapter=新的SelectorListAdapter(活动、R.layout.row_布局、SmallTank2ListInfo 1阵列);
SelectorListAdapter适配器2=新的SelectorListAdapter(活动、R.layout.row_布局、SmallTank2ListInfo阵列);
SelectorListAdapter适配器3=新的SelectorListAdapter(活动、R.layout.row_布局、SmallTank2ListInfo阵列);
SelectorListAdapter适配器4=新的SelectorListAdapter(活动、R.layout.row_布局、SmallTank2ListInfo 4Array);
//将阵列适配器设置为listview
setAdapter(适配器);
ListView2.setAdapter(适配器2);
listViewThree.setAdapter(适配器3);
listViewFour.setAdapter(适配器4);
公共类SelectorListAdapter扩展了ArrayAdapter{
阵列列表对象;
语境;
int textViewResourceId;
私有字符串模板标签;
检查私有布尔值;
公共选择器ListAdapter(上下文,int textViewResourceId,
ArrayList对象){
超级(上下文、textViewResourceId、对象);
this.context=上下文;
this.textViewResourceId=textViewResourceId;
this.objects=对象;
}

事实上你自己已经回答了所有问题

对于4个独立的
arrayLists
,使用相同的
arrayAdapter
类如何? --是的,你可以用

要识别不同的
arrayAdapter
s,您可以将变量传递给存储在局部变量中的构造函数。根据此变量的值,您可以决定要执行的操作

调用super类的构造函数时,请保留此变量并调用
super
()

对4个单独的ArrayList使用相同的arrayAdapter类如何?-不要这样做。问题是我需要arrayAdapter知道输入了4个ArrayList中的哪一个-然后将附加值传递给适配器以标识列表、整数、对象、
enum
等。