1

我正在使用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()。但是没有什么能让我的代码正常工作。

4

0 回答 0