Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-15506: fix editText layout issue for header/footerView #4797

Merged
merged 2 commits into from
Oct 18, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a check for the type of focusedView, eg. if (focusedView instanceof EditText) {...}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind.

}
}
}
}
Expand Down