Child Fragment的ListView不令人耳目一新

时间:2013-08-20 21:05:59

标签: android android-fragments android-listfragment

我正在使用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()。但没有任何东西使我的代码工作。

0 个答案:

没有答案