回到那个 activity 时空白的 viewpager
blank viewpager when back to that activity
我有这个代码:
...
ArrayList<View> views = new ArrayList<>();
ArrayList<String> titulos = new ArrayList<>();
views.add(viewPlan);
views.add(viewPerfil);
titulos.add("Planes");
titulos.add("Perfil");
ViewPager oPager = (ViewPager) getView().findViewById(R.id.pager);
oPager.setOffscreenPageLimit(3);
oPager.setAdapter(new FormAdapter(((FragmentActivity)getActivity()).getSupportFragmentManager(), views, titulos));
和这个适配器:
class FormAdapter extends FragmentStatePagerAdapter {
List<SolapaSocioFragment> solapas;
ArrayList<View> views = new ArrayList<>();
ArrayList<String> titulos = new ArrayList<>();
public FormAdapter(FragmentManager fm, ArrayList<View> views, ArrayList<String> titulos) {
super(fm);
solapas = new ArrayList<SolapaSocioFragment>();
this.views = views;
this.titulos = titulos;
for (int i = 0; i < views.size(); i++ ){
solapas.add(new SolapaSocioFragment().newInstance(views.get(i)));
}
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
return new SolapaSocioFragment().newInstance(views.get(position));
}
@Override
public int getCount() {
return views.size();
}
@Override
public CharSequence getPageTitle(int position) {
return titulos.get(position);
}
}
视图寻呼机显示视图,但是当我转到其他 activity 并按下后退按钮时,视图是空白的,我在 google 上看到问题是我必须使用 getChildFragmentManager( ) 而不是 (FragmentActivity)getActivity()).getSupportFragmentManager() 但 childFragmentManager 与 FragmentStatePagerAdapter 的构造函数不兼容, FragmentPagerAdapter.What 会是问题吗?谢谢
问题是我在后台堆栈中使用 replace
而不是 add
。
我有这个代码:
...
ArrayList<View> views = new ArrayList<>();
ArrayList<String> titulos = new ArrayList<>();
views.add(viewPlan);
views.add(viewPerfil);
titulos.add("Planes");
titulos.add("Perfil");
ViewPager oPager = (ViewPager) getView().findViewById(R.id.pager);
oPager.setOffscreenPageLimit(3);
oPager.setAdapter(new FormAdapter(((FragmentActivity)getActivity()).getSupportFragmentManager(), views, titulos));
和这个适配器:
class FormAdapter extends FragmentStatePagerAdapter {
List<SolapaSocioFragment> solapas;
ArrayList<View> views = new ArrayList<>();
ArrayList<String> titulos = new ArrayList<>();
public FormAdapter(FragmentManager fm, ArrayList<View> views, ArrayList<String> titulos) {
super(fm);
solapas = new ArrayList<SolapaSocioFragment>();
this.views = views;
this.titulos = titulos;
for (int i = 0; i < views.size(); i++ ){
solapas.add(new SolapaSocioFragment().newInstance(views.get(i)));
}
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
return new SolapaSocioFragment().newInstance(views.get(position));
}
@Override
public int getCount() {
return views.size();
}
@Override
public CharSequence getPageTitle(int position) {
return titulos.get(position);
}
}
视图寻呼机显示视图,但是当我转到其他 activity 并按下后退按钮时,视图是空白的,我在 google 上看到问题是我必须使用 getChildFragmentManager( ) 而不是 (FragmentActivity)getActivity()).getSupportFragmentManager() 但 childFragmentManager 与 FragmentStatePagerAdapter 的构造函数不兼容, FragmentPagerAdapter.What 会是问题吗?谢谢
问题是我在后台堆栈中使用 replace
而不是 add
。