美文网首页
RecyclerView item中EdiTtext处理

RecyclerView item中EdiTtext处理

作者: R_雨泽 | 来源:发表于2018-06-06 19:46 被阅读0次
    效果图

    遇到的问题

    TextWatcher 的afterTextChanged  方法会被执行多次,尤其切换tab之后 ,adapter 数据重新设置 ,但是仍然会执行多次,最开始不得不用线程池去监听  next button  状态;

    解决方法

    @Override

        public void onBindViewHolder(RecyclerView.ViewHolder holder,final int position) {

    if (holder ==null)return;

    //        final int pos = holder.getAdapterPosition();

            final LoginconfigFieldRsp data =datas.get(position);

    if (holderinstanceof AccountViewHolder) {

    final AccountViewHolder accountViewHolder = (AccountViewHolder) holder;

    //避免TextWatcher被调用,提前将他移除。

                if (accountViewHolder.accountinput.getTag()instanceof ExpandTextWatcher) {

    accountViewHolder.accountinput.removeTextChangedListener((ExpandTextWatcher) (accountViewHolder.accountinput.getTag()));

    }

    accountViewHolder.accoundlab.setText(data.getLabel());

    accountViewHolder.accountinput.setText(data.getInputvalue());

    accountViewHolder.accountinput.setHint(String.format(tips, data.getLabel()));

    accountViewHolder.accountinput.setOnFocusChangeListener(new ExpandOnFocusChangeListener(position, accountViewHolder.ivaccountclear, data));

    if (data.isShowClear()) {

    accountViewHolder.ivaccountclear.setVisibility(View.VISIBLE);

    }else {

    accountViewHolder.ivaccountclear.setVisibility(View.INVISIBLE);

    }

    accountViewHolder.ivaccountclear.setOnClickListener(new View.OnClickListener() {

    @Override

                    public void onClick(View v) {

    data.setInputvalue("");

    accountViewHolder.accountinput.setText("");

    accountViewHolder.accountinput.setHint(String.format(tips,data.getLabel()));

    notifyItemChanged(position);

    }

    });

                ExpandTextWatcher expandTextWatcher =new ExpandTextWatcher(position, accountViewHolder.ivaccountclear, data);

    accountViewHolder.accountinput.addTextChangedListener(expandTextWatcher);

    accountViewHolder.accountinput.setTag(expandTextWatcher);

    }

    }

    相关文章

      网友评论

          本文标题:RecyclerView item中EdiTtext处理

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