By default, an EditText view retains its state โ this is done by setting flags in the code that point to the view in order to maintain state when the view is not displayed or focus is lost. Text is automatically saved and restored after the device is rotated. You can disable automatic saving of EditText mode state in the XML layout file by setting the android: saveEnabled property to false:
android:saveEnabled="false"
Or programmatically call view.setSaveEnabled(false) .
saveEnabled determines whether this view state will be saved (that is, whether its onSaveInstanceState () method will be called). Note that even if freezing is enabled, the view still needs to have an identifier assigned to it (via setId ()) to save state. This flag can only disable saving this view; all child views can keep their state. the saveEnabled attribute is part of android View - View code . Here are some parts of the code:
public boolean isSaveEnabled() { return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; }
...
public void setSaveEnabled(boolean enabled) { setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); }
...
void setFlags(int flags, int mask) { int old = mViewFlags; mViewFlags = (mViewFlags & ~mask) | (flags & mask); int changed = mViewFlags ^ old; if (changed == 0) { return; } int privateFlags = mPrivateFlags; if (((changed & FOCUSABLE_MASK) != 0) && ((privateFlags & HAS_BOUNDS) !=0)) { if (((old & FOCUSABLE_MASK) == FOCUSABLE) && ((privateFlags & FOCUSED) != 0)) { clearFocus(); } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) && ((privateFlags & FOCUSED) == 0)) { if (mParent != null) mParent.focusableViewAvailable(this); } }
....
Wildroid
source share