listview edittext 焦点问题
作者:
tigg | 来源:发表于
2017-04-12 17:18 被阅读57次// 定义变量,记录刷新前获得焦点的EditText所在的位置
int mCurrentTouchedIndex = -1;
private View.OnTouchListener onTouch = new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v instanceof EditText) {
EditText et = (EditText) v;
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.setSelection(et.length());
} else {
ViewHolder holder = (ViewHolder) v.getTag();
holder.getView(R.id.number).setFocusable(false);
holder.getView(R.id.number).setFocusableInTouchMode(false);
}
return false; }};
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
mCurrentTouchedIndex = position;
} }});
editText.setOnTouchListener(onTouch);
v.setOnTouchListener(onTouch);if (mCurrentTouchedIndex == position) {
editText.requestFocus();
editText.setSelection(fileTitle.length());
}
本文标题:listview edittext 焦点问题
本文链接:https://www.haomeiwen.com/subject/fidzvttx.html
网友评论