[英]I want to restore my orientation in fragment.
I am using onSaveInstanceState(Bundle outState) and passing a int value in PutInt , but in my onActivitycreated method when i am trying to getInt then it is showing exception saying , Key android:view_state expected Bundle but value was a android.util.SparseArray. 我正在使用onSaveInstanceState(Bundle outState)并在PutInt中传递一个int值,但在我的onActivitycreated方法中,当我尝试getInt然后它显示异常说,Key android:view_state期望Bundle但值是android.util.SparseArray。 The default value was returned. 返回了默认值。
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mListView = getListView();
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
if (savedInstanceState !=null) {
mCheckedPosition = savedInstanceState.getInt(STATE_CHECKED_POSITION, -1);
}
..................
Here i am sending the value . 我在这里发送价值。 it is fine here. 这里很好。 problem is in when i am getting it. 问题是在我得到它的时候。
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_CHECKED_POSITION, mCheckedPosition);
Log.d(AppConstants.TAG,"STATE_CHECKED_POSITION"+mCheckedPosition );
}
I would put super.onSaveInstanceState(outState);
我会把super.onSaveInstanceState(outState);
after putting int into bundle. 把int放入bundle之后。
What is value of Your 'STATE_CHECKED_POSITION' ? 你的'STATE_CHECKED_POSITION'有什么价值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.