RecyclerView中EditText在设置map、TextWatcher之后仍然数据混乱

在使用RecyclerVew时当item中包括EditText时。我使用的解决的办法是:添加TextWatcher,当EditText修改之后将修改的内容保存到map中然后滑动RecyclerView时,通过Position定位map中的数据,在重新将数据填充到RecyuclerView的item中,这样发现一个问题,就是我们没有修改EditText中内容的时候也会回调TextWatcher,所以需要做的就是在适当的时候添加TextWatcher,不需要时就将这个监听器移除掉下面直接把代码放上来

 final MyTextWatcher myTextWatcher = new MyTextWatcher(position);
            holder.et_Device_Information.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View view, boolean b) {
                    if (b) {
                        holder.et_Device_Information.addTextChangedListener(myTextWatcher);
                    } else {
                        holder.et_Device_Information.removeTextChangedListener(myTextWatcher);
                    }
                }
            });

TextWatcher我是写了一个内部内继承的TextWatcher 比较简单就不放上来了

你可能感兴趣的:(AS)