适配器刷新的时候,edittext中textwatcher被重复调用的问题,解决方法是先删除一遍,可以通过设置tag的方式
@Override protected void convert(BaseViewHolder baseViewHolder, final PeoPle person) { EditText et=baseViewHolder.getView(R.id.note); baseViewHolder.setText(R.id.name,person.getName()); if (et.getTag()!=null && et.getTag() instanceof TextWatcher){ et.removeTextChangedListener((TextWatcher) et.getTag()); et.clearFocus(); } et.setText(person.getNote()); 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) { String content= s.toString().trim(); person.setNote(content); } @Override public void afterTextChanged(Editable s) { } }; et.addTextChangedListener(watcher); et.setTag(watcher); }
另外数据新增或者删除的时候,焦点会自动跳转到第一个item的edittext中,解决方法是把数据所在的recyclerview的焦点去除
rv.setFocusable(false); rv.setFocusableInTouchMode(false);