How to change particular image in recycler view after clicking

前端 未结 4 1966
别那么骄傲
别那么骄傲 2021-02-03 16:04

I want to change respective image of clicked item in recycler view. Now whats happening is if i click on item 2 image is changing at random item position in the list

<         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-03 16:27

    in onBindViewHolder add following code:

    testImage.setTag(holder);

    then, in onClick add this code to change image:

    MyRecyclerViewAdapter.DataObjectHolder  yourHolderObj = (MyRecyclerViewAdapter.DataObjectHolder)((ImageView)itemView.findViewById(R.id.logo)).getTag();
    
    yourHolderObj.testImage.setImageResource(R.drawable.video_icon_fill);
    

提交回复
热议问题