我有一个textView和一个editText的listView。当用户修改editText的值时,我会保存一个新的对象。我实现了一个TextWatcher,但我无法检索到引用editText修饰的特定textView的值。有人帮助我吗?addTextChangedListener保存一个新的对象
编辑
TextWatcher为ListView控件的具体线路
quantity.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
if(!s.toString().isEmpty()){
if (Integer.parseInt(s.toString())!=0){
HashMap<Products, Integer> into = new HashMap<Products, Integer>();
Products pr = new Products();
//product contains value of textView
pr.set_id(Integer.parseInt(product.get("id")));
pr.setNome(product.get("nome"));
into.put(pr, Integer.parseInt(s.toString()));
pArrayList.add(into);
cart.setProdotti(pArrayList);
}
}
}
}
能否请您分享您的代码添加textWatcher? –
好的,我已经完成了! –
在afterTextChanged()你想获得不同的TextView的值?对不起,但我真的不知道你的问题... –