填充由FragmentPagerAdapter创建后创建的ListFragment

时间:2011-11-07 20:58:32

标签: android android-fragments android-viewpager

我的Fragmentactivity在onCreate方法中启动AsyncTask,并且还创建了一个FragmentPagerAdapter,它在getItem方法中初始化3 ListFragments(如本例中的http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.html)。但是如何在onPostExecute中填充片段列表?

我尝试将Fragments ID保存在Map中并将它们从FragmentPagerAdapter中返回,但这总是会导致NullPointerExceptions ...

    @Override
    public ListFragment getItem(int position) {
        ListFragment newFragment = ArrayListFragment.newInstance(position);
        FragmentTable.put(position,newFragment.getId());
        return newFragment;
    }

    public ListFragment getInitializedItem(int postition) {
        return (ListFragment) fm.findFragmentById(FragmentTable.get(postition));
    }

0 个答案:

没有答案