Pattabi Raman
Pattabi Raman

Reputation: 5854

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?

Upvotes: 1

Views: 353

Answers (1)

Marek Sebera
Marek Sebera

Reputation: 40621

Simply join those two Lists 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);

Upvotes: 4

Related Questions