简体   繁体   中英

How to add more than one List<String> in Android?

How to assign more than one List in 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);

Here dh.selectInct1(); returns a list that is assigned into inc . Now I need to add one more list from database to this already existing inc . How to achieve it?

Simply join those two List s using 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM