RecyclerView item中EdiTtext处理

效果图

遇到的问题

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);

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 详情页面 packagecom.example.shoppingcar; importandroid.conten...
    ForCrazyLove阅读 583评论 0 2
  • 先Activity的抽象类 BaseActivity [java]view plaincopy /** *Acti...
    Zaker2Magic阅读 998评论 0 0
  • 今天发微信给Z:电影看过么?好看? 过了半个小时,他回:值得看的 突然忧伤莫名。 记得以前他说:你是了解我的,要不...
    9198b4fcf27e阅读 229评论 0 0
  • 在春天,学校的草坪上星星点点的都是蒲公英。 蒲公英没有脚,等风来的时候,随着风一直飘。 正如它的花语“停不了的爱,...
    qikooo阅读 378评论 0 1
  • 木桶饭42 苦瓜炒蛋 干锅千叶豆腐 板栗排骨 茶树菇排骨 奶盖绿茶18 脉动*2矿泉水*1 10元 木屋烧烤84 ...
    書蟲三號阅读 244评论 0 0