Skip to content Skip to sidebar Skip to footer

Multiple Listview Inside Listfragment

I have been working on trying to implement two listviews inside a list fragment, I have stated two list views in my xml and tried to set two seperate sets of data in the java file

Solution 1:

You need to set the two adapters accordingly with each ListView....

ListViewlist= (ListView)findViewById(R.id.list);
ListViewlist2= (ListView)findViewById(R.id.list2);

list.setAdapter(...)
list2.setAdapter(...)

...however you do not have two ListViews in play. In using a ListFragment each time you call setAdapter you are setting a singleListView to the given contents. You would need to adjust your ListFragement to be that of a Fragment and have two separate ListViews within the Fragment, then set each with its own adapter as mentioned above.

Solution 2:

setListAdapter assumes the default target. To set the second adapter you need to find the second listview id and then set the second adapter to it.

listview = findViewById(R.id.list2);
listview.setAdapter(adapter2);

Note that a listfragment usually expects only a single list so the above.might not work, you may need to just use a regular fragment and do the above.for both lists.

Post a Comment for "Multiple Listview Inside Listfragment"