I've a NavigationDrawer to start fragments. I've a fragment with 4 tabs from TabPageIndicator
with fragments which contains a listview.
If I click the entry in the menu again which launches the fragment, the elements are gone. Sometimes if I switch between them they are gone too. I also have to swipe sometimes to get them back.
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 using from an example
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
similar to ArchivTabAdapter
update 1
it seems, that I've to scroll over all items (especially the last one) to get the others back