安卓fragment-如何保存的意见片段状态时,另一个片段被压在它上面 [英] android fragment- How to save states of views in a fragment when another fragment is pushed on top of it

查看:158
本文介绍了安卓fragment-如何保存的意见片段状态时,另一个片段被压在它上面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中,片段(比如弗拉加)被添加到backstack和另一个片段(比如 FragB )到达此上方。现在的回击弗拉加来的顶部和 onCreateView()被调用。现在,我在一个特定的国家不得不弗拉加 FragB 得到了推在它的上面。

In android, a fragment (say FragA) gets added to the backstack and another fragment (say FragB) comes to the top. Now on hitting back FragA comes to the top and the onCreateView() is called. Now I had FragA in a particular state before FragB got pushed on top of it.

我的问题是我怎么能恢复弗拉加其previous状态?有没有一种方法来保存状态(如在一个Bundle说),如果是的话,我应该覆盖哪些方法?

My Question is how can I restore FragA to its previous state ? Is there a way to save state (like say in a Bundle) and if so then which method should I override ?

推荐答案

片段指南 FragmentList例如,你可以找到:

In fragment guide FragmentList example you can find:

@Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("curChoice", mCurCheckPosition);
    }

,你可以这样以后使用:

Which you can use later like this:

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
            // Restore last state for checked position.
            mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
        }
}

我在片段的初学者,但它似乎是你的问题的解决方案;) OnActivityCreated是从后堆栈段返回后调用。

I'm a beginner in Fragments but it seems like solution of your problem ;) OnActivityCreated is invoked after fragment returns from back stack.

这篇关于安卓fragment-如何保存的意见片段状态时,另一个片段被压在它上面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆