Witam
Do tej pory miałem do czynienia z trzema fragmentami na jednej aktywności gdzie był umieszczony był: ViewPager i FragmentStatePagerAdapter z trzema zakładkami. Wyszukiwanie fragmentów robiłem właśnie w klasie bazującej na FragmentStatePagerAdapter:
...
public class TabsPagerAdapter extends FragmentStatePagerAdapter {
private static SparseArray<Fragment> fragmentReferenceArray;
private static int NUM_ITEMS = 3;
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
fragmentReferenceArray = new SparseArray<Fragment>();
}
@Override
public Fragment getItem(int index) {
switch (index) {
case 0:
Fragment customersFragment = CustomersFragment.newInstance();
fragmentReferenceArray.put(index, customersFragment);
return customersFragment;
case 1:
Fragment productsFragment = ProductsFragment.newInstance();
fragmentReferenceArray.put(index, productsFragment);
return productsFragment;
case 2:
Fragment positionsBufferFragment = PositionsBufferFragment.newInstance();
fragmentReferenceArray.put(index, positionsBufferFragment);
return positionsBufferFragment;
}
return null;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
fragmentReferenceArray.remove(position);
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
switch (position) {
case 0:
CustomersFragment customersFragment = (CustomersFragment) super.instantiateItem(container, position);
fragmentReferenceArray.put(position, customersFragment);
return customersFragment;
case 1:
ProductsFragment productsFragment = (ProductsFragment) super.instantiateItem(container, position);
fragmentReferenceArray.put(position, productsFragment);
return productsFragment;
case 2:
PositionsBufferFragment positionsBufferFragment = (PositionsBufferFragment) super.instantiateItem(container, position);
fragmentReferenceArray.put(position, positionsBufferFragment);
return positionsBufferFragment;
}
return null;
}
public Fragment getFragment(int id) {
return fragmentReferenceArray.get(id);
}
}
Tylko chyba przy takim "wizardzie" to nie przejdzie.
Jak mogłaby wyglądać taka aktywność z np. 15 fragmentami ze stałymi przyciskami "Dalej ->" i "Anuluj X" korzystając z intencji w komunikacji i przełączaniem między nimi?
Pozdrawiam
M.K.