How Do I Clear Edittext After All Fragments Above It Have Been Popped?
In an Android project, I have 3 fragments, and I navigate through them during an operation the user does. FragmentA -> FragmentB -> FragmentC When the user finishes the ope
Solution 1:
This can be easily done using flags.
The idea is that when the popBackStack() is called, the Activity sets a flag which will be checked by FragmentA in its onResume().
Simplified steps:
When popping off FragmentC, do this:
clearEditTextOfA = true;in
onResume()of FragmentA, do this:if (activityCallback.shouldClearEditText()) { editText.setText(""); }The
activityCallbackis an interface which lets a Fragment communicate with the Activity it is placed in. See Android Docs.Instead of doing
ft.add(), doft.replace().This will make the
onResume()of your Fragments get called whenever they change.
Post a Comment for "How Do I Clear Edittext After All Fragments Above It Have Been Popped?"