Dynamically adding Views in a RecyclerView only to current item

前端 未结 8 2023
一向
一向 2020-12-20 12:08

I\'m dynamically adding Views to my items in a RecyclerView. These added Views should only be related to the item which they\'re added to, but I\'m having a pro

8条回答
  •  攒了一身酷
    2020-12-20 12:49

    You need to track what views have been added based on the backing data. I would probably add any necessary extra views in onBindViewHolder(), and remove any that might be present in onViewRecycled(). Then when you want to make one appear dynamically, change whatever variable you have tracking whether it should be visible, and call notifyItemChanged().

提交回复
热议问题