简体   繁体   English

我想在片段中恢复我的方向。

[英]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.

相关问题 我想在片段中为回收者视图实现一个搜索栏。 我在片段中尝试了以下代码,但它不起作用 - I want to implement a searchbar for recycler view in a fragment. I have tried the below code in my fragment but it is not working 我想将数据从活动转移到片段,然后在片段中显示数据。 我的代码不起作用 - I want to transfer data from activity to fragment and then display data in the fragment. My code doesn't work 我想在片段中的webview上的Android应用程序中加载地图。 我在下面使用以下代码 - I want to load map inside my android application on webview within a fragment. I use following code below 片段方向改变。 恢复视图状态 - Orientation change in Fragment. Restoring view state 方向在BottomNavigationView片段的recyclerview中不起作用。 在哪里设置方向属性? - Orientation is not working in recyclerview in BottomNavigationView Fragment. Where to set orientation attribute? 想要在片段中使用回收器视图。 设置适配器时创建了一个适配器,它显示错误 - Want to use a recycler view in a fragment. Created an adapter when I set the adapter it shows me error getContext()方法在片段中返回null。 将上下文保存在变量中是一个好主意吗? 我想了解利弊 - getContext() method returns null in fragment. Is it a good idea to keep the context in a variable? I want to understand the pros and cons 如何在ListViewAdapter和Fragment之间发送变量。 - How can I send a variable between my ListViewAdapter to my Fragment. 如果我使用 gridview 将选定的图像传递给第二个片段,如果我想将选定的图像传递给第二个到第三个片段。 那会怎么办? - if I pass selected image using gridview to second fragment , If I want to selected image pass second to third fragment. then how will do? 添加片段时我的应用程序崩溃。 这是为什么? 我该如何解决? - My app crash when I add a Fragment. Why is that? How I can fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM