android列表edittext使用TextWatcher数据混乱问题

在listView或recycleView中使用edittext , 当需要对输入数据进行监听是 , 容易发生数据混乱

适用购物车金额批量修改 , 单独修改

	 EditText eidttext= h.getView(R.id.eidttext);
     if (eidttext.getTag() != null 
     && eidttext.getTag() instanceof  TextWatcher) 
     {
        eidttext.removeTextChangedListener((TextWatcher)eidttext.getTag());
     }
     eidttext.setText(object.getValue); 
     TextWatcher textWatcher = new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                    //对列表中的数据集合进行刷新,并刷新列表
                            delwithAcount();
                    }
                };
                eidttext.addTextChangedListener(textWatcher);
                eidttext.setTag(textWatcher);

说明:

因为在复用的列表中 , 对控件进行了服用 , 但是没有对输入框监听进行复用 , 所以会导致输入框输入监听的数据混乱 , 好在控件有一个setTag方法 , 我们可以将每个item的edittext进行设置setTag保存他的TextWathcer并在每次创建edittext时判断当前的editext时候定义过TextWathcer , 如果有进行回收 , 并再次创建 , 便可以做到数据的不混乱 .

注意:

     eidttext.setText(object.getValue); 
     TextWatcher textWatcher = new TextWatcher();

设置一定要在设置textWathcer前进行edittext的赋值 , 否则无效

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio中,可以通过使用AutoCompleteTextView来实现点击下拉列表可滑动的功能。AutoCompleteTextView是EditText的一个子类,它提供了自动完成文本的功能,并且可以显示一个下拉列表供用户选择。 要实现点击下拉列表可滑动的功能,可以按照以下步骤进行操作: 1. 在XML布局文件中添加AutoCompleteTextView控件: ```xml <AutoCompleteTextView android:id="@+id/autoCompleteTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionThreshold="1" /> ``` 其中,completionThreshold属性指定了在用户输入几个字符后开始显示下拉列表。 2. 在Java代码中设置适配器和数据源: ```java AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data); autoCompleteTextView.setAdapter(adapter); ``` 其中,data是一个包含下拉列表选项的字符串数组或集合。 3. (可选)如果需要自定义下拉列表的样式,可以创建一个自定义的布局文件,并在适配器中指定该布局文件: ```java ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.custom_dropdown_item, data); ``` 其中,custom_dropdown_item是自定义布局文件的名称。 这样,当用户点击AutoCompleteTextView时,就会显示一个下拉列表供用户选择,并且可以滑动浏览列表中的选项。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值