我有一个ListView,每行包含一个EditText。当我尝试在EditText中更改行的值时,其他一些editText值会自动更改。
下面是listView和EditText的代码。
<ListView
android:id="@+id/ListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:cacheColorHint="#ffffff"
android:layout_above="@+id/includeID"
android:layout_below="@+id/linearlayoutforSubTotal"
android:visibility="invisible" >
</ListView>
<EditText
android:id="@+id/editTex"
android:layout_width="60dip"
android:layout_height="30dip"
android:textColor="#000000"
android:textSize="12dip"
android:inputType="number"
android:editable="true" >
</EditText>
以下是我试图获取EditText的更改值的代码。
item.quantity.setId(position);
item.quantity.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus){
final int position = v.getId();
final EditText Caption = (EditText) v;
ShoppingCartHelper.cartItems.get(position).qty = Integer.parseInt(Caption.getText().toString());
}
}
});
请帮我找到解决此问题的方法
答案 0 :(得分:0)
尝试这样的事情:
editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// Set the value of the field to s.toString();
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing.
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing.
}
});