美文网首页
RecycleView使用动态添加含有Editext的item

RecycleView使用动态添加含有Editext的item

作者: hao_developer | 来源:发表于2019-11-19 22:10 被阅读0次

实现效果图

微信图片_20191119221003.jpg 微信图片_20191119221011.jpg 微信图片_20191119221016.jpg 微信图片_20191119221021.jpg

问题:调用adapter中的notifyDataSetChanged方法就提示:Cannotcall this method while RecyclerView is computing a layout or scrolling 翻译为:当RecyclerView正在计算布局或滚动时,无法调用此方法

分析:View布局中的item复用问题

holder.edContent!!.tag = position
        holder.ivClose!!.tag = position

        if (tip.equals(strList.get(position))) {
            holder.edContent!!.setHint(tip)
            holder.edContent!!.setHintTextColor(context.resources.getColor(R.color.hui))
           holder.edContent!!.setText("")
        } else {
            holder.edContent!!.setText((strList.get(position)))
        }

        holder.edContent!!.setOnFocusChangeListener { v, hasFocus ->
            if (!hasFocus){
                if(strList.size > v!!.tag as Int){
                    strList.set(v!!.tag as Int,(v as EditText)!!.editableText.toString())
                }
            }
        }

        holder.ivClose!!.setOnClickListener {
            if (listener != null){
                listener!!.onAdappterViewClick(it.tag as Int,1,null,null)
            }
        }

image.png

相关文章

网友评论

      本文标题:RecycleView使用动态添加含有Editext的item

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