How to keep fragment view state?

随声附和 提交于 2019-12-02 16:19:17

问题


I have doubt in fragment system.

I have two fragments like A and B

If i move A to B,

Navigation.findNavController(v).navigate(R.id.B)

Now A fragment onDestroyView is called i know it's normal. After in B Fragment i called PopBackStack

Navigation.findNavController(v).popBackStack()

now A fragment onViewCreated is called i also know it's normal. Now A fragment all ui is initial state.

My question is how to keep A fragment UI State like recyclerview scroll position, FAB button visibility, etc


回答1:


You have to store recyclerview scroll position, FAB button visibility in a variable and set those values after onViewCreated is called.

OR

You can store it in Bundle of onSaveInstanceState and retain its state

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}


来源:https://stackoverflow.com/questions/57765679/how-to-keep-fragment-view-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!