在ListView和onItemClick调焦的EditText

在ListView和onItemClick调焦的EditText

本文介绍了在ListView和onItemClick调焦的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每个的ListView 项目我有的EditText

当我设置机器人:可调焦=假的EditText 然后 onItemClick 的ListView 项工作,但的EditText 没有得到光标时,我点击里。

When I set android:focusable="false" for EditText then onItemClick on the ListView item is working, but EditText doesn't get cursor when I click inside.

如果我将设置机器人:可调焦=真正的的EditText ,然后的EditText 可获得焦点,但 onItemClick 的ListView 不,当我点击工作就可以了。

If I'll set android:focusable="true" for EditText, then EditText is focusable, but onItemClick for the ListView doesn't work when I click on it.

如何分离 onItemClick 在此项目可成为焦点的EditText

How to separate onItemClick and focusable EditText in this item?

推荐答案

由于 @ user370305 与OnTouchListener的想法。现在,它为我工作用 setOnTouchListener()

Thanks @user370305 for the idea with OnTouchListener.Now it is working for me by using setOnTouchListener():

public class AdapterListCards extends CursorAdapter implements View.OnTouchListener {
 public AdapterListCards(Context context) {
    super(context, null, true);
 }

 @Override
 public boolean onTouch(View view, MotionEvent motionEvent) {
    if (view instanceof EditText) {
        EditText editText = (EditText) view;
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
    } else {
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.edtCode.setFocusable(false);
        holder.edtCode.setFocusableInTouchMode(false);
    }
    return false;
 }

 private class ViewHolder {
    TextView txtName;
    EditText edtCode;
}

 @Override
 public View newView(final Context context, Cursor cursor, ViewGroup parent) {
    View convertView = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
    final ViewHolder holder = new ViewHolder();
    holder.txtName = (TextView) convertView.findViewById(R.id.txt_name);
    holder.edtCode = (EditText) convertView.findViewById(R.id.pass);
    holder.edtCode.setOnTouchListener(this);
    convertView.setOnTouchListener(this);
    convertView.setTag(holder);

    return convertView;
 }

@Override
public void bindView(View view, Context context, Cursor cur) {
    ViewHolder holder = (ViewHolder) view.getTag();
    if (cur!=null) holder.txtName.setText(cur.getString(cur.getColumnIndex("name")));
 }
}

和课程:机器人:windowSoftInputMode =adjustPan在清单活动

这篇关于在ListView和onItemClick调焦的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:18