Fragment reload, Edittext not cleared

In my fragment there are a lot of lines and editing text, and the submit button is for saving data, the reset button is reset for all elements (Editing texts and spinners). I used the following code to reset all controls

FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.detach(this).attach(this).commit(); 

but it does not clear editext. All spinners are reset, but editext text remains as it is

+3
android android-edittext reset android-fragments fragmentmanager
Jun 16 '17 at 4:50
source share
2 answers

detach (). detach () does not work after updating the support library 25.1.0 (may be earlier). This solution works fine after the upgrade:

Note:

use runOnUiThread () to use commitNowAllowingStateLoss

  getSupportFragmentManager() .beginTransaction() .detach(oldFragment) .commitNowAllowingStateLoss(); getSupportFragmentManager() .beginTransaction() .attach(oldFragment) .commitAllowingStateLoss(); 
0
Jun 16 '17 at 5:02
source share

Try the following:

  FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.remove(this).replace(R.id.container, YourFragment.newInstance());; ft.commit(); 

Performance note: if you only replace a fragment with reset values ​​only, then its value is better than resetting the value manually, because replacing the entire fragment involves a lot of additional overhead compared to manually resetting the values.

0
Jun 16 '17 at 6:53 on
source share



All Articles