multiple listview inside listfragment

梦想的初衷 提交于 2019-12-01 11:33:30

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

ListView list = (ListView)findViewById(R.id.list);
ListView list2 = (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 single ListView 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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!