Why my notifyItemChanged() change the wrong item of RV?

霸气de小男生 提交于 2020-01-16 19:37:48

问题


I have button at my RV item. After clicking I show progress bar and send request to my API. When response will be successful I would like to hide progress bar and change background of button. Here I click on my button:

holder.ivAddTo.setOnClickListener {
            holder.progressBar.visibility = View.VISIBLE
            holder.ivAddTo.setBackgroundResource(R.drawable.added_to_notepad)
            holder.ivAddTo.visibility = View.GONE
            holder.ivAddTo.isClickable = false

            saveToNotepad(jobModel.id)


        }

my api call method part:

  if (response.isSuccessful) {
                    Toast.makeText(ctx, "Added to notepad", Toast.LENGTH_SHORT).show()
                    notifyItemChanged(view.getTag(R.id.tag_3) as Int, 1)
                }

my second OnBindViewHolder():

override fun onBindViewHolder(holder: JobsHolder, position: Int, payloads: List<Any>) {
        if (payloads.isNotEmpty()) {
            when (payloads[0]) {
                1 -> {
                    holder.ivAddTo.visibility = View.GONE
                }
            }
        } else {
            super.onBindViewHolder(holder, position, payloads);
        }
    }

my problem - after 200 response my app changes the last visible item at RV why does it happen and how I can solve this problem?

来源:https://stackoverflow.com/questions/56344319/why-my-notifyitemchanged-change-the-wrong-item-of-rv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!