Skip to content

Commit

Permalink
Fix for retaining focus, issue #13
Browse files Browse the repository at this point in the history
This change saves the EditText's focus status in the saved state and restores it with the first measure.
  • Loading branch information
IanGClifton committed Oct 21, 2014
1 parent a4e325c commit 947ccac
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -52,6 +52,7 @@ public class FloatLabel extends FrameLayout {
private static final String SAVE_STATE_KEY_LABEL = "saveStateLabel";
private static final String SAVE_STATE_PARENT = "saveStateParent";
private static final String SAVE_STATE_TAG = "saveStateTag";
private static final String SAVE_STATE_KEY_FOCUS = "saveStateFocus";

/**
* Reference to the EditText
Expand Down Expand Up @@ -267,6 +268,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mEditText.onRestoreInstanceState(childState);
childState = mSavedState.getParcelable(SAVE_STATE_KEY_LABEL);
mLabel.onRestoreInstanceState(childState);
if (mSavedState.getBoolean(SAVE_STATE_KEY_FOCUS, false)) {
mEditText.requestFocus();
}
mSavedState = null;
}
measureChild(mEditText, widthMeasureSpec, heightMeasureSpec);
Expand Down Expand Up @@ -297,6 +301,7 @@ protected Parcelable onSaveInstanceState() {
final Bundle saveState = new Bundle();
saveState.putParcelable(SAVE_STATE_KEY_EDIT_TEXT, mEditText.onSaveInstanceState());
saveState.putParcelable(SAVE_STATE_KEY_LABEL, mLabel.onSaveInstanceState());
saveState.putBoolean(SAVE_STATE_KEY_FOCUS, mEditText.isFocused());
saveState.putBoolean(SAVE_STATE_TAG, true);
saveState.putParcelable(SAVE_STATE_PARENT, superState);

Expand Down

0 comments on commit 947ccac

Please sign in to comment.