Hai i’m new to this fragments development in android. My Question is navigation between the fragments. I have a button in fragment 1 and a text view in fragment2 and i have activity activity1 where i declared both these fragments in xml. My question is when i press the button in fragment1, it has to carry some text and display in the textview of fragment2 before that it has to check whether the fragment2 is in the same layout or not?
Code will be very helpful to me. Thanks in advance……….
At first declare your inflater into onCreateView (in 2ndFragmentClass) like below:
Please consider fragment_content must at lease have a TextView inside itself (So that we set its value inside the fragment). Then we have to change the value of this text from the 1st fragment. So we add this constructor inside our 2nd Fragment (the fragment containing TextView) like below:
Simply, it would be like below:
Then we must define which text must be set into 2nd Fragment from 1stFragmentClass. Then we set the text of the 2nd fragment by pressing button in 1st fragment like below: