1

I created a viewpager views following this topic. I am using only one fragment with instances.

So, I need to save a text (from editText) from each fragment to load them all after reopening app, but I don't know how. I think I just misunderstood how to properly use Instances..

I am really confused and don't know what to do. Maybe just some referal to tut how to correctly use this or a better construction of ViewPager should help.

-thx for any help (:

Community
  • 1
  • 1
  • As i understand u have several fragments in VIewPager and each of this fragments have EditText field ? The goal is saveing EditText Fields and restore it after app reload again ? Yes ? – Max Vitruk May 15 '15 at 20:30
  • Yes, the fragments have same layout, but different content in EditText field and I want to restore them after reload. – Tomáš Petrovčín May 15 '15 at 20:39

1 Answers1

0

I have idea how yo implement your view pager to your requirements) First we gone look how it works :

  1. ViewPages load fragment #1 and same time he loads fragment #2
  2. When you sliding fragment #2 it loads fragment #3 and keep in mind #1
  3. We slide to #3, fragment #4 loading , #2in mind, #1 - destroy and go on. So we need save info when fragment destroy it self and load when it will appear.

It means you need to construct your fragment in the next way:

  1. create method getNewInstance(args...) like in your following topic.
  2. @Override OnCreate(..) method to handle you Bundle object. Unwrap it.
  3. @Override OnCreateView(...) method to inject all views. Include your "EditText"
  4. Override onStop(...) for example. It means your fragment will out of view pager visible bounds. In this method save your EditText.getText() to SharedPreferences and use as key - your arguments from bundle.toString().
  5. Look again into onCreateView method. Get saved text by same key and put into your EDIT text view.

So how it works ? - your viewPager make fragment and upload text to editTextView from memory file (sharedPreferences). User can make some changes and slide out. When this fragment breaks all info rewrite into same cell into memory (SharedPreferences) by same key. Good luck

Community
  • 1
  • 1
Max Vitruk
  • 413
  • 3
  • 8