viewpagerindicator:列表视图在片段中为空,第二次显示为空

viewpagerindicator: listview empty in fragment empty on second time showing

我有一个 NavigationDrawer 来启动片段。我有一个片段,其中包含来自 TabPageIndicator 的 4 个选项卡以及包含列表视图的片段。

如果我再次单击启动片段的菜单中的条目,元素就会消失。有时,如果我在它们之间切换,它们也会消失。我有时也必须滑动才能将它们取回。

ArchivFragment

public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
    View view = layoutInflater.inflate(R.layout.fragment_archiv, viewGroup, false);
    
    List<String> titles=new ArrayList<String>();
    titles.add(getString(R.string.category_animal));
    titles.add(getString(R.string.category_earth));
    titles.add(getString(R.string.category_water));
    titles.add(getString(R.string.category_air));
    
    FragmentPagerAdapter adapter = new ArchivTabAdapter(getFragmentManager(), titles);

    ViewPager pager = (ViewPager)view.findViewById(R.id.pager);
    pager.setAdapter(adapter);

    TabPageIndicator indicator = (TabPageIndicator)view.findViewById(R.id.indicator);
    indicator.setViewPager(pager);
    
    return view;
}

ArchivTabAdapter 使用示例

public class ArchivTabAdapter extends FragmentPagerAdapter {

    private List<String> tabs;

    public ArchivTabAdapter(FragmentManager fm, List<String> tabs) {
        super(fm);
        this.tabs = tabs;
    }

    @Override
    public Fragment getItem(int position) {
        return ArchivListFragment.newInstance(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabs.get(position % tabs.size()).toUpperCase(Locale.getDefault());
    }

    @Override
    public int getCount() {
        return tabs.size();
    }
}

ArchivListFragment

public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
    View view = (View) inflater.inflate(R.layout.archiv_list, viewGroup, false);
    
    ListView lv = (ListView) view.findViewById(R.id.tab);
    
    ArrayList<Item> al = new ArrayList<Item>();
    
    al = getArrayListToApply(filter);
    
    lv.setAdapter(new ArchivArrayAdapter(getActivity(), al));
    
    return view;
}

ArchivArrayAdapter

类似于ArchivTabAdapter

更新 1

看来,我必须滚动所有项目(尤其是最后一个)才能恢复其他项目

ArchivTabAdapter
similar problem

android.support.v4.app.FragmentPagerAdapterandroid.support.v4.app.FragmentStatePagerAdapter