RecyclerView嵌套多个布局,多个editText,解决文本输入框上下交换位置中的值问题

话不多说直接上代码,希望能解决你们的问题,有不理解的可以给我留言

if (((ViewHolder_a) holder).editText.getTag() instanceof TextWatcher) {
    ((ViewHolder_a) holder).editText.removeTextChangedListener((TextWatcher) (((ViewHolder_a) holder).editText.getTag()));
}

    ((ViewHolder_a) holder).editText.setText(((Item_a) list.get(position)).getEditText());


TextWatcher watcher = 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) {
        if (TextUtils.isEmpty(editable.toString())) {
            ((Item_a)list.get(position)).setEditText("");
        } else {
            ((Item_a) list.get(position)).setEditText(editable.toString());
        }
    }
};
((ViewHolder_a) holder).editText.addTextChangedListener(watcher);
((ViewHolder_a) holder).editText.setTag(watcher);

你可能感兴趣的:(android,RecyclerView,EditText,scrollView)