【发布时间】:2012-10-01 18:22:38
【问题描述】:
我有一个带有一些 textView 和一个 editText 的 listView。当用户修改editText的值时,我会保存一个新对象。我实现了一个 TextWatcher,但我无法检索引用 editText 修改的特定 textView 的值。有人帮帮我吗?
编辑
listView 特定行的TextWatcher
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的值吗?对不起,我真的不明白你的问题......
-
我有一个包含很多产品的 listView,对于每一个我都有一个 3 TextView:名称、价格、描述。现在我添加一个editText。当我修改这个 editText 时,我会保存一个新对象的实例。我的问题是将 textView 的值检索到 TextWatcher
-
你需要为每个TextView分配一个唯一的id,然后在afterTextChanged()中你可以通过为每个id调用findViewById()来获取textView的值。
-
添加了一些示例代码。如果我误解了克劳迪奥,请告诉我。
标签: android android-listview android-edittext textwatcher