在Android中捕获Listview中的TextChanged事件

在Android中捕获Listview中的TextChanged事件,android,listview,Android,Listview,我有一个包含EditText的ListView。我想捕获此文本框的textchanged事件并更新其他列 在我的自定义适配器中,我做到了这一点 public View getView(int position, View inView, ViewGroup parent) { View v = inView; if (v == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemS

我有一个包含EditText的ListView。我想捕获此文本框的textchanged事件并更新其他列

在我的自定义适配器中,我做到了这一点

public View getView(int position, View inView, ViewGroup parent) {
    View v = inView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.cartlistview, null);
    }

    EditText edQty = (EditText) v.findViewById(R.id.cartProductQuantity);
    edQty.addTextChangedListener(new QtyChangedWatcher(position, v));
}
即使用户没有更改任何内容,事件也会自动触发。此外,当用户仅更改第一行的输入时,会触发该事件,但listview中的所有文本框都会触发该事件

我做错什么了吗

谢谢

试试这个:

public View getView(int position, View inView, ViewGroup parent) {
    View v = inView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.cartlistview, null);

    EditText edQty = (EditText) v.findViewById(R.id.cartProductQuantity);
    edQty.addTextChangedListener(new QtyChangedWatcher(position, v));
    }
}

(将addTextChangedListener移到if条件内)

创建
活动时,是否有任何
EditText
对象具有焦点?我不确定我所做的是否正确。在偶数代码中,我检查前后的值,如果它们不同,则继续我的代码。我使用setTag函数将上一个值存储在文本框中。