返回该活动时,空白的viewpager

时间:2016-07-22 20:38:53

标签: android android-fragments android-viewpager android-view is-empty

我有这段代码:

...
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);
        }
    }

视图寻呼机显示视图,但当我去其他活动并按后退按钮时,视图为空白,我在谷歌上看到问题是我必须使用getChildFragmentManager()而不是(FragmentActivity)getActivity()) .getSupportFragmentManager()但是childFragmentManager与FragmentStatePagerAdapter和FragmentPagerAdapter的构造函数不兼容。这会是什么问题?感谢

1 个答案:

答案 0 :(得分:0)

问题是我在后台堆中使用了//Log analytics result into bundle Bundle bundle = new Bundle(); Player player = PreferencesHelper.getPlayer(getActivity()); bundle.putString("QuizName",mCategory.getName()); bundle.putString("Questions",Integer.toString(iCount)); bundle.putInt("CorrectAnswers",iSolve); bundle.putFloat("CorrectAnsRatio",(float)(iSolve *100.0)/iCount); mFirebaseAnalytics.logEvent("UserData",bundle); 而不是replace