如何在Android中分配多个列表?
List<String> inc = dh.selectInct1();
ArrayAdapter<String> inc1 = new ArrayAdapter<String>(this,R.layout.list,R.id.textViewx,inc);
lvinc.setAdapter(inc1);
lvinc.setOnItemClickListener(this);
此处dh.selectInct1();
会返回分配到inc
的列表。现在我需要从数据库中再添加一个列表到现有的inc
。如何实现呢?
答案 0 :(得分:4)
只需使用List
addAll(Collection c)
即可
List<String> inc = dh.selectInct1();
List<String> inc2 = dh.selectInct2(); //select your data to second list
inc.addAll(inc2); // join them together
ArrayAdapter<String> inc1 = new ArrayAdapter<String>(this,R.layout.list,R.id.textViewx,inc);
lvinc.setAdapter(inc1);
lvinc.setOnItemClickListener(this);