Reloading Fragment, Edittext's Text Not Cleared
In my fragment there are lot of spinner and edit text and submit button is to save data, reset button is to reset all elements(Edit Texts and Spinners). I have used folllowing cod
Solution 1:
detach().detach() not working after support library update 25.1.0 (may be earlier). This solution works fine after update:
note:
use runOnUiThread() to use commitNowAllowingStateLoss
getSupportFragmentManager()
.beginTransaction()
.detach(oldFragment)
.commitNowAllowingStateLoss();
getSupportFragmentManager()
.beginTransaction()
.attach(oldFragment)
.commitAllowingStateLoss();
Solution 2:
Try this one :
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(this).replace(R.id.container, YourFragment.newInstance());;
ft.commit();
Performance note : if you are only replacing the fragment just to reset the values then its better to reset the values manually because replacing the entire fragment involves lot of extra overhead as compared to manually resetting values.
Post a Comment for "Reloading Fragment, Edittext's Text Not Cleared"