1

Inside Select Case I used this

getFragmentManager().beginTransaction()
.replace(R.id.frame_entry, new fragment_1())
.addToBackStack(null)
.commit();

to switch between fragments, but I have a problem with it. The fragment contains EditText with a pre-selected values. When I go to fragment_2 and then return to fragment_1 the selected value on my EditText is gone. How can I make the value stay?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
myown email
  • 139
  • 1
  • 10

1 Answers1

0

This will probably Fragment Guide help.

Override onSaveInstanceState like this.

 @Override
 public void onSaveInstanceState(Bundle outState) {
 super.onSaveInstanceState(outState);
 outState.putInt("curChoice", mCurCheckPosition);
}

Then you can use it later

 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
 super.onActivityCreated(savedInstanceState);
 if (savedInstanceState != null) {
    // Restore last state for checked position.
    mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
 }
}

OnActivityCreated is invoked after fragment returns from back stack.

Anubhav Gupta
  • 2,492
  • 14
  • 27