[英]Orientation change in Fragment. Restoring view state
I have a fragment, which hold some EditTexts
, some RadioGroups
and Spinners
. 我有一个片段,其中包含一些
EditTexts
,一些RadioGroups
和Spinners
。
When I change the orientation the view state isn't retained. 更改方向时,不会保留视图状态。
I tried to override onSavaInstanceState
and call setRetainInstance(true)
, but it doesn't helped. 我试图重写
onSavaInstanceState
并调用setRetainInstance(true)
,但没有帮助。
I also tried to save all inserted values in the Bundle outState
like this: outState.putString("name", mName.getText().toString())
and restore it in onCreateView
. 我还尝试将所有插入的值保存在
Bundle outState
如下所示: outState.putString("name", mName.getText().toString())
并将其还原到onCreateView
。
Doesn't helped either, the Bundle outState
in onCreateView
hold the values, but I can't manipulate the views to set the value to it. 也没有帮助,
onCreateView
的Bundle outState
保留值,但是我无法操纵视图来为其设置值。 For example like this: mName.setText(savedInstanceState.getString("name"))
例如这样的示例:
mName.setText(savedInstanceState.getString("name"))
Any ideas how to solve it? 有什么想法如何解决吗?
I had replaced the Fragment
in the FragmentActivity
, this caused tha fact that the state wasn't restored properly. 我取代了
Fragment
在FragmentActivity
,这引起了塔事实状态没有被正确还原。
I surrounded the Fragment
committing with if (savedInstanceState == null)
in the onCreate
method. 我在
onCreate
方法中用if (savedInstanceState == null)
提交了Fragment
。
Also I used the Bundle outState
and onSaveInstanceState
of the Fragment
to restore the state in tha same Fragment
properly. 我还使用了
Fragment
的Bundle outState
和onSaveInstanceState
来正确恢复同一Fragment
的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.