Answer the question
In order to leave comments, you need to log in
How to insert an unusual fragment in ViewPager?
How to insert an unusual fragment in ViewPager?
There is a ViewPager with fragments. The adapter takes data from an array and fragments are created based on this array:
/**
* Адаптер для ViewPager с шагами
*/
public class StepsAdapter extends FragmentStatePagerAdapter {
private List<StepsMenuItem> mSteps;
public StepsAdapter(FragmentManager fm, List<StepsMenuItem> steps) {
super(fm);
mSteps = steps;
}
@Override
public Fragment getItem(int position) {
return StepFragment.newInstance(mSteps.get(position).getFileName());
}
/**
* Возвращает количество шагов
*
* @return Количество шагов
*/
@Override
public int getCount() {
return mSteps.size()+1;
}
}
Answer the question
In order to leave comments, you need to log in
You can do this:
Some interface:
interface Item {
Fragment getFragment()
}
class StepItemImpl implements Item {
private StepsMenuItem data;
StepItemImpl(StepsMenuItem data) {
this.data = data;
}
@Override
public Fragment getFragment() {
return StepFragment.newInstance(data.getFileName());
}
}
class WhatNextImpl implements Item {
@Override
public Fragment getFragment() {
return WhatNextFragment.newInstance(...);
}
}
List<Item> mItems;
...
@Override
public Fragment getItem(int position) {
return mItems.get(position).getFragment();
}
...
@Override
public int getCount() {
return mItems.size()+1;
}
/code>
Как-то так.
You can make your own analog getItemType (int position) as in the classic adapter from ListView
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question