简体   繁体   English

片段方向改变。 恢复视图状态

[英]Orientation change in Fragment. Restoring view state

I have a fragment, which hold some EditTexts , some RadioGroups and Spinners . 我有一个片段,其中包含一些EditTexts ,一些RadioGroupsSpinners

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. 也没有帮助, onCreateViewBundle 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. 我取代了FragmentFragmentActivity ,这引起了塔事实状态没有被正确还原。

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. 我还使用了FragmentBundle outStateonSaveInstanceState来正确恢复同一Fragment的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM