title: Trying to change the drawable of Image view on clicking it in list adapter
body: <p>Actually the problem is when I click on image view of a single item its drawable is changing but many other random items have their image views changing as well with that click. Below is my code for the list adapter. I have seen the solution for this problem from some sources and I found that setting tags and then setting on click listeners works but it is not working for me. For reference, addMealItem is the id of the view which is to be changed when clicked. I have even added toast to test what is wrong but the toast is not very helpful in this situation.</p>
  <pre><code>
  class FoodsAdapter(application: Application, val context: Context, val clickListener: MealItemclickListener) : ListAdapter&lt;MealItemModel, FoodsAdapter.ViewHolder&gt;(MealItemDiffCallBack()) {
      val database = MealItemDatabase.getInstance(application)
  
      class ViewHolder private constructor(val binding: MealitemBinding) : RecyclerView.ViewHolder(binding.root) {
          fun bind(item: MealItemModel, clickListener: MealItemclickListener, context: Context, database: MealItemDatabase) {
              binding.food = item
              GlobalScope.launch {
                  withContext(Dispatchers.IO) {
                      if(database.mealItemDao.getBreakfastItem(item.itemTitle)!=null) {
                          if (database.mealItemDao.getBreakfastItem(item.itemTitle).likedOrNot) {
                              binding.addmealItem.setTag(&quot;unliked&quot;)
                              withContext(Dispatchers.Main){
                                  Toast.makeText(context,&quot;Unliked&quot;,Toast.LENGTH_LONG).show()
                              }
                              binding.addmealItem.setImageResource(R.drawable.ic_add_button)
                          } else {
                              withContext(Dispatchers.Main){
                                  Toast.makeText(context,&quot;Liked&quot;,Toast.LENGTH_LONG).show()
                              }
                              binding.addmealItem.setTag(&quot;liked&quot;)
                              binding.addmealItem.setImageResource(R.drawable.ic_add_button_filled)
                          }
                      }
                  }
              }
              binding.addmealItem.setOnClickListener {
                  clickListener.onClick(item)
                  GlobalScope.launch {
                      withContext(Dispatchers.IO) {
                          if(database.mealItemDao.getBreakfastItem(item.itemTitle)!=null) {
                              if (database.mealItemDao.getBreakfastItem(item.itemTitle).likedOrNot) {
                                  binding.addmealItem.setTag(&quot;unliked&quot;)
                                  withContext(Dispatchers.Main){
                                      Toast.makeText(context,&quot;Unliked&quot;,Toast.LENGTH_LONG).show()
                                  }
                                  binding.addmealItem.setImageResource(R.drawable.ic_add_button)
                                  database.mealItemDao.getBreakfastItem(item.itemTitle).likedOrNot = false
                              } else {
                                  binding.addmealItem.setTag(&quot;liked&quot;)
                                  withContext(Dispatchers.Main){
                                      Toast.makeText(context,&quot;Liked&quot;,Toast.LENGTH_LONG).show()
                                  }
                                  binding.addmealItem.setImageResource(R.drawable.ic_add_button_filled)
                                  database.mealItemDao.getBreakfastItem(item.itemTitle).likedOrNot = true
                              }
                          }
                      }
                  }
              }
  
  //            binding.addmealItem.setOnClickListener {
  //                clickListener.onClick(item)
  //                if (binding.addmealItem.drawable.constantState!!.equals(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_add_button, null)!!.constantState)) {
  //                    binding.addmealItem.setImageResource(R.drawable.ic_add_button_filled)
  //                } else {
  //                    binding.addmealItem.setImageResource(R.drawable.ic_add_button)
  //                }
  //            }
              binding.executePendingBindings()
          }
  
          companion object {
              fun from(parent: ViewGroup): ViewHolder {
                  val layoutInflater = LayoutInflater.from(parent.context)
                  val binding = MealitemBinding.inflate(layoutInflater, parent, false)
                  return ViewHolder(binding)
              }
          }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          return ViewHolder.from(parent)
      }
  
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          val item = getItem(position)
          holder.bind(item, clickListener, context, database)
      }
  }
  
  class MealItemDiffCallBack : DiffUtil.ItemCallback&lt;MealItemModel&gt;() {
      override fun areItemsTheSame(oldItem: MealItemModel, newItem: MealItemModel): Boolean {
          return oldItem == newItem
      }
  
      override fun areContentsTheSame(oldItem: MealItemModel, newItem: MealItemModel): Boolean {
          return oldItem.itemTitle == newItem.itemTitle
      }
  }
  
  class MealItemclickListener(val clickListener: (foodTitle: String) -&gt; Unit) {
  //    var flag = false
      fun onClick(mealItem: MealItemModel) {
  //        flag = !flag
          return clickListener(mealItem.itemTitle)
      }
  }  
  
  </code></pre>