0

I have an activity and in that activity I have 2 Fragments A and B.

Fragment A has a EditText for entering Email.

Fragment B contains 2 more fragments B1 and B2 which can be selected using two buttons at the bottom of Fragment B.

B1 and B2 contain an EditText for entering Name and Number.

When i enter Email, Name and Number and switch between fragments A and B, Email value retains BUT the Name and Number values in sub-fragments B1 and B2 gets lost.

Is it because i have nested fragments in B?

How can i retain the values of sub-fragments B1 and B2?

I am new to android, Can anybody refer a good working example?

Kazmi
  • 593
  • 1
  • 6
  • 24
  • This might be relevant: http://stackoverflow.com/questions/20550016/savedinstancestate-is-always-null-in-fragment/20552273#20552273 – mach Mar 11 '15 at 13:14

1 Answers1

0

It's always a pain working with 2+ fragments.

Not the best workaround: Try using SharedPreferences to save and display Name and Number, and reload the entire activity when needed so that changes get effected.

Sajith Sageer
  • 163
  • 3
  • 16
  • As i am new with android so I was testing it with the text fields .... In reality i will displaying 2 different ListViews in Fragments A and B. And i don't want my list views to loose the values. – Kazmi Mar 16 '15 at 14:05
  • Are you using tabs to switch between fragments? – Sajith Sageer Mar 16 '15 at 17:50
  • I am selecting Fragment A and B from a menu which slides in from left, and Fragment B has two button at the bottom with which you can switch between sub-fragments B1 and B2. – Kazmi Mar 19 '15 at 10:03
  • i have found 2 solutions but don't know which one is efficient so would like your suggestions, please see the link, i appreciate your help so far. http://stackoverflow.com/questions/29275746/retain-fragment-with-show-hide-or-save-fragment-data-in-a-file-which-one-is-eff – Kazmi Mar 26 '15 at 10:10
  • In my project I used 'replace' a lot, to change fragments and ended up having many problems. So I would say go with the first solution. – Sajith Sageer Mar 28 '15 at 09:59
  • what kind of problems you faced? because so far 'replace' is working perfectly. – Kazmi Mar 31 '15 at 08:53