Android MVP with view pager
private class MyAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragement(Fragment fragment){
mFragmentList.add(fragment);
}
}
use it in activity:
MyAdapter adapter = new MyAdapter(getChildFragmentManager());
Fragment fragment1 = EmptyFragment.newInstance("this is page 1");
Fragment fragment2 = EmptyFragment.newInstance("this is page 2");
presenter1.setxxx(fragment1);
presenter2.setxxx(fragment2);
adapter.addFragement(fragment1);
adapter.addFragement(fragment2);
viewPager.setAdapter(adapter);