问题
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