RecyclerView布局中解决edittext监听错乱

步骤一.根据Tag移除掉监听

if (hold.et.getTag() instanceof TextWatcher){
    hold.et.removeTextChangedListener ((TextWatcher) hold.et.getTag());
}

步骤二.set文字

hold.et.setText("");

步骤三.添加一个监听

TextWatcher watcher = new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
               
                }
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }
                @Override
                public void afterTextChanged(Editable s) {             
                        String trim = hold.et.getText().toString().trim();
                        mList.get(position).setName(trim);
                
                }
            };
hold.et.addTextChangedListener(watcher);

步骤四,设置一个Tag

hold.et.setTag(watcher); 
注意:顺序不要乱
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页