I have linked a switch to shift from Fragment1 to Fragment2 but I do not know how to return to Fragment1 if the switch is clicked again.
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
Do not put the switch inside fragment. You should include the switch in parent layout and change the fragment when switch is clicked.
For eg;
You include switch in linear layout below that layout you have framelayout in which you are committing the fragments.
A possible solution: use
switch.setOnCheckedChangeListener
andtransaction.replace
. For example:}
R.id.your_fragment_container
is a layout for your two fragments