开发者

Android: Preserve complex view data of Fragments

In my application I have a FragmentActivity that uses a FragmentViewPager. The Fragments have a quite complex structure of views with ListViews and Adapters. The FragmentViewPager appears to destroy the Fragments that are out 开发者_C百科of sight, and to recreate them if the user swipes back to it. This leads to all member variables are cleared that hold the lists and adapters with all content, so the Fragment is empty if it comes back to the top.

My question now is: How can I preserve these data? If I'm not mistaken, I have to save and resume the list with the content the adapter works on. When and where should I save it?

Is it a good idea to save the data in the FragmentActivity or in a helper singleton class outside the activity?


How can I preserve these data?

Your data is already "preserved". You loaded it from somewhere originally from some data model. Load it again.

If there are changes the user is making on-screen to the data, you need to be persisting that to your data model as the user makes the changes. This is no different than dealing with, say, a RatingBar in a ListView row.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜