首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >保存新对象的addTextChangedListener

保存新对象的addTextChangedListener
EN

Stack Overflow用户
提问于 2012-10-01 18:22:38
回答 2查看 558关注 0票数 0

我有一个listView,有一些textView和一个editText。当用户修改editText的值时,我会保存一个新对象。我实现了一个TextWatcher,但无法检索特定textView的值,该值引用了修改过的editText。有人帮我吗?

编辑

TextWatcher用于listView的特定行

代码语言:javascript
复制
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);
            }
        }
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-01 18:55:23

代码语言:javascript
复制
<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();
    ...
}
票数 2
EN

Stack Overflow用户

发布于 2012-10-01 18:29:38

也许这有点过火了,但是您可以在每一行中使用setTag()方法来实现TextView和EditText的视图,所以这两个视图都会通过这个键连接起来。然后只需调用findViewByTag()即可。这个操作有点昂贵,所以一定要在用户停止写操作时才调用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12678803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档