我正在使用nested-fragment
,在parent fragment
内,有一个child fragment
包含listview
。我将父片段放在backStack
中,当我恢复它时,listview
没有重新创建/刷新。而不是相同的listItem
附加在下面。
这是我在child fragment
中添加parent fragment
的代码:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FragmentTransaction transaction = getChildFragmentManager()
.beginTransaction();
transaction.replace(R.id.fragment_container, chapterFragment); // chapterFragment is declared and initialized globally in the class
transaction.commit();
}
这是我的孩子片段:
public class ChaptersListFragment extends SherlockListFragment {
ArrayAdapter<String> mAdapter = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
List<String> items = new ArrayList<String>();
for (int i = 0; i < CompetitiveProgramming.chapterList.size(); i++) {
items.add(CompetitiveProgramming.chapterList.get(i).chapterTitle);
}
mAdapter = new ArrayAdapter<String>(getSherlockActivity(),
R.layout.list_layout, items);
setListAdapter(mAdapter);
}
}
我也试过了notifyDataSetChanged()
。但没有任何东西使我的代码工作。