Missing TextView data(text) in a fragment


I have a few edittexts and textviews in Fragment A. I use edittexts to get value from user and then I calculate based on my formula and show the result in the textview.



For example Edittext A has 1 and Edittext B has 2 and my formula is add so the textview will show the result as 3.



Also, there is a button, info on the Fragment A. On clicking this button a new fragment B is displayed using the below code:



Now, when I press the back button, I let the system call super.onBackPressed() so that the current Fragment B is removed and I get back Fragment A.



MY PROBLEM:



Now the edittexts retain all their values, however the value I calculated and displayed on TextViews disappears.



I checked onViewStateRestored(Bundle savedInstanceState) method however the parameter savedInstanceState is null.



My Question:



How do I save/retrieve the values for my textviews?



OR



where can I call that code again that calculates the data for textviews ??



Using SharedPreferences will solve your issue just save them in sharedPreferences and clear SharedPreference after Use.



To resolve this problem you need use some data layer like Shared Preference or SQL storage. In some primitive way it looks like:



Think also about MVP and Presenter. It is also be available.
In open source you can find amazing MVP library called moxy. It can restore your view state.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

The Dalles, Oregon

眉山市

清晰法令