在fragment 中使用listview ,跳转到其他页面在返回时数据丢失了,解决方法如下:
fragment返回时数据列表丢失,因为listview其实已经换了,直接调用adapter的notifyDataSetChanged就没有对listview进行setAdapter;
需要重新setadapter一下,重写个方法进行刷新
private void notifyDataSetChanged() {//
if (adapter == null) {
adapter = new TopicListAdapter(mActivity, topicLists, true);
}
lv.setAdapter(adapter);
}
在Android开发中,当从一个Fragment返回到另一个Fragment时,如果ListView的数据列表丢失,通常是因为适配器未正确更新。本文提供了一个解决方法,通过在Fragment中重写notifyDataSetChanged()方法来确保适配器正确更新ListView,从而避免数据丢失问题。
4279

被折叠的 条评论
为什么被折叠?



