There is a fragment that contains Spinners and Edit Texts. The user fills them in and then moves to another fragment to perform some actions there. When it comes back to the first fragment with data from frag2, you need to restore or write down programmatically what it entered before.
I do this:
Fragment 1
in onCreateView
Bundle bdReStore = getArguments(); if (bdReStore != null) { String fs = bdReStore.getString("editTemp"); Log.i(LOG_TAG, "recieve: " + editTemp); editTemp.setText(fs); } in the transition code to frag2 (onClick implemented)
Frag1 frag1 = new Frag1(); Frag2 frag2 = new Frag2(); Bundle bundleStore = new Bundle(); if (addTask.getText().length() != 0) { bundleStore.putString("editTemp", editTemp.getText().toString();); /** сохранить строку, если введена */ } frag1.setArguments(bdReStore); android.app.FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content_frame, frag2).commit(); Fragment 2
Frag1 frag1 = new Frag1(); Bundle bundle = new Bundle(); bundle.putInt("tag", toothCount); frag1.setArguments(bundle); android.app.FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content_frame, frag1).commit(); I think that the problem is in the second fragment (frag2), when I return to the first one. Because here you have to re-create a new instance of frag1. Therefore, null is displayed to me in LogCat.
Question: What needs to be changed in the code to implement the idea?
Sentence:
There was a thought to make a hardcode : transfer from frag1 to frag2, and then back from frag2 to frag1. But I think that there is a more humane way.
myUpdate 01 Part of my code, which is now working. I wrote about it above: http://pastebin.com/6cz1BL98
addToBackStack(). - tim_taller