保存视图寻呼机状态

保存视图寻呼机状态

本文介绍了Android:保存视图寻呼机状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存视图寻呼机状态,以避免在方向更改时再次创建片段.任何建议都非常感谢.

I am trying to save view pager state, in order to avoid creating fragments once again on orientation change. Any suggestions is highly appreciated.

我尝试了下面的东西,但不确定它会如何工作......

I tried below stuff, but not sure how it will work...

    int pagerId = 0;

        mPager = (ViewPager) findViewById(R.id.pager);
        DialerPagerAdapter viewpageradapter = new DialerPagerAdapter(fm);
        if (savedInstanceState != null) {
            if (savedInstanceState.getInt("tab") != -1) {
               mPager.setCurrentItem(savedInstanceState.getInt("tab"));
                pagerId=savedInstanceState.getInt("pagerState");
            }
        }
        mPager.setOnPageChangeListener(ViewPagerListener);
        if (pagerId != -1 ){
            mPager.setId(pagerId);
        }else{
            pagerId=mPager.getId();
        }
        mPager.setAdapter(viewpageradapter);

在 saveInstanceState 中我正在做下面的事情

in saveInstanceState I am doing below stuff

outState.putInt("pagerState" , mPager.getId() );

谢谢文卡特拉曼

推荐答案

这样做

<activity
    android:name="yourActivityeThatContainsViewPager"
    android:configChanges="keyboardHidden|orientation|screenSize"
/>

这篇关于Android:保存视图寻呼机状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 23:12