美文网首页
RecyclerView中EditText数据错乱问题

RecyclerView中EditText数据错乱问题

作者: Colin高宏杰 | 来源:发表于2020-08-11 16:45 被阅读0次

解决方式

第一步:找ID,判断是否设置输入框Tag,移除
第二步:输入框设置后台返回的数据
第三步:输入框创建并添加监听事件
第四步:输入框设置Tag

//      第一步
        EditText mEtEmpName = helper.getView(R.id.item_et_empname);
        EditText mEtProjectName = helper.getView(R.id.item_et_projectname);
        EditText mEtProjectId = helper.getView(R.id.item_et_projectid);
        EditText mEtAddress = helper.getView(R.id.item_et_address);
        EditText mEtDriver = helper.getView(R.id.item_et_driver);
        EditText mEtTelrochare = helper.getView(R.id.item_et_telrochare);
        EditText mEtBz = helper.getView(R.id.item_et_bz);
        EditText mEtOrther = helper.getView(R.id.item_et_orther);


        if (mEtEmpName.getTag() != null && mEtEmpName.getTag() instanceof TextWatcher) {
            mEtEmpName.removeTextChangedListener((TextWatcher) mEtEmpName.getTag());
        }
        if (mEtProjectName.getTag() != null && mEtProjectName.getTag() instanceof TextWatcher) {
            mEtProjectName.removeTextChangedListener((TextWatcher) mEtProjectName.getTag());
        }
        if (mEtProjectId.getTag() != null && mEtProjectId.getTag() instanceof TextWatcher) {
            mEtProjectId.removeTextChangedListener((TextWatcher) mEtProjectId.getTag());
        }
        if (mEtAddress.getTag() != null && mEtAddress.getTag() instanceof TextWatcher) {
            mEtAddress.removeTextChangedListener((TextWatcher) mEtAddress.getTag());
        }
        if (mEtDriver.getTag() != null && mEtDriver.getTag() instanceof TextWatcher) {
            mEtDriver.removeTextChangedListener((TextWatcher) mEtDriver.getTag());
        }
        if (mEtTelrochare.getTag() != null && mEtTelrochare.getTag() instanceof TextWatcher) {
            mEtTelrochare.removeTextChangedListener((TextWatcher) mEtTelrochare.getTag());
        }
        if (mEtBz.getTag() != null && mEtBz.getTag() instanceof TextWatcher) {
            mEtBz.removeTextChangedListener((TextWatcher) mEtBz.getTag());
        }
        if (mEtOrther.getTag() != null && mEtOrther.getTag() instanceof TextWatcher) {
            mEtOrther.removeTextChangedListener((TextWatcher) mEtOrther.getTag());
        }
//       第二步:
        mEtEmpName.setText(item.getApplyEmpName());
        mEtProjectName.setText(item.getProjectName());
        mEtProjectId.setText(item.getProjectId());
        mEtAddress.setText(item.getAddress());
        mEtDriver.setText(item.getDriver());
        mEtTelrochare.setText(item.getTelRoChare());
        mEtBz.setText(item.getBz());
        mEtOrther.setText(item.getOrther());
//       第三步
        TextWatcher watcher1 = 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) {

                item.setApplyEmpName(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher2 = 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) {

                item.setProjectName(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher3 = 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) {

                item.setProjectId(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher4 = 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) {

                item.setAddress(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher5 = 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) {

                item.setDriver(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher6 = 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) {

                item.setTelRoChare(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher7 = 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) {

                item.setBz(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        TextWatcher watcher8 = 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) {

                item.setOrther(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        };
        mEtEmpName.addTextChangedListener(watcher1);
        mEtProjectName.addTextChangedListener(watcher2);
        mEtProjectId.addTextChangedListener(watcher3);
        mEtAddress.addTextChangedListener(watcher4);
        mEtDriver.addTextChangedListener(watcher5);
        mEtTelrochare.addTextChangedListener(watcher6);
        mEtBz.addTextChangedListener(watcher7);
        mEtOrther.addTextChangedListener(watcher8);
//        第四步
        mEtEmpName.setTag(watcher1);
        mEtProjectName.setTag(watcher2);
        mEtProjectId.setTag(watcher3);
        mEtAddress.setTag(watcher4);
        mEtDriver.setTag(watcher5);
        mEtTelrochare.setTag(watcher6);
        mEtBz.setTag(watcher7);
        mEtOrther.setTag(watcher8);

相关文章

网友评论

      本文标题:RecyclerView中EditText数据错乱问题

      本文链接:https://www.haomeiwen.com/subject/nqeydktx.html