我有一个listView,有一些textView和一个editText。当用户修改editText的值时,我会保存一个新对象。我实现了一个TextWatcher,但无法检索特定textView的值,该值引用了修改过的editText。有人帮我吗?
编辑
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);
}
}
}
}发布于 2012-10-01 18:55:23
<TextView android:id="@+id/p1_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Product 1" />
<TextView android:id="@+id/p1_price"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="20" />
public void afterTextChanged(Editable s) {
...
String price = ((TextView) findViewById(R.id.p1_price)).getText();
...
}发布于 2012-10-01 18:29:38
也许这有点过火了,但是您可以在每一行中使用setTag()方法来实现TextView和EditText的视图,所以这两个视图都会通过这个键连接起来。然后只需调用findViewByTag()即可。这个操作有点昂贵,所以一定要在用户停止写操作时才调用它。
https://stackoverflow.com/questions/12678803
复制相似问题