2012-02-05 75 views
4

我有一個包含EditText的ListView。我想要捕獲此文本框的textchanged事件並更新其他列。在Android的Listview中捕獲TextChanged事件

裏面我customAdapter我這樣做

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)); 
} 

的事件越來越對自己解僱,即使用戶沒有改變任何東西。此外,當用戶僅更改第一行的輸入時,該事件將被觸發,但對於列表視圖中的所有文本框。

我做錯了什麼?

感謝

+0

是否有任何的'EditText'對象都具有焦點,當你'Activity'產生的? – teoREtik 2012-02-05 12:29:25

+0

我不確定我做的是否正確。在我的代碼中,我檢查了值之前和之後的值,如果它們不同,我繼續執行我的代碼。我使用setTag函數在文本框中存儲了以前的值。 – Arun 2012-07-14 06:50:12

回答

0

試試這個:

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如果條件內)