Skip to content

Commit

Permalink
Merge pull request #4797 from hieupham007/timob-13686-v4
Browse files Browse the repository at this point in the history
timob-15506: fix editText layout issue for header/footerView
  • Loading branch information
pingwang2011 committed Oct 18, 2013
2 parents bb729f9 + c5e1244 commit 9ee94a5
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import android.view.ViewParent;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -112,9 +113,15 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
OnFocusChangeListener focusListener = null;
View focusedView = listView.findFocus();
int cursorPosition = -1;
if (focusedView != null) {
OnFocusChangeListener listener = focusedView.getOnFocusChangeListener();
if (listener != null && listener instanceof TiUIView) {
//Before unfocus the current editText, store cursor position so
//we can restore it later
if (focusedView instanceof EditText) {
cursorPosition = ((EditText)focusedView).getSelectionStart();
}
focusedView.setOnFocusChangeListener(null);
focusListener = listener;
}
Expand Down Expand Up @@ -144,6 +151,10 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
//Ok right now focus is with listView. So set it back to the focusedView
focusedView.requestFocus();
focusedView.setOnFocusChangeListener(focusListener);
//Restore cursor position
if (cursorPosition != -1) {
((EditText)focusedView).setSelection(cursorPosition);
}
}
}
}
Expand Down

0 comments on commit 9ee94a5

Please sign in to comment.