无法从Parcelable恢复viewPager状态

时间:2012-09-07 06:09:44

标签: android android-viewpager

在我的CustomPageAdapter类中,我已经实现了这两种方法来恢复viewPager状态。为了测试它,为了简单起见,我尝试传递整数并检索它但是我仍然得到0.这是方法实现:

 @Override
 public void restoreState(Parcelable state, ClassLoader arg1) {
 if (state instanceof Bundle) {
    Bundle bundle = (Bundle) state;
    saved = bundle.getInt("stateToSave");
    super.restoreState(bundle.getParcelable("instanceState"), arg1);
    return;
 }
 super.restoreState(state, arg1);
 }

 @Override
 public Parcelable saveState() {
    Bundle bundle = new Bundle();
    bundle.putParcelable("instanceState", super.saveState());
    bundle.putInt("stateToSave", 8);
    return bundle;
 }

0 个答案:

没有答案