1

I have a RecyclerView. Every layout contains expandle view within itself. With item click expandle view of clicked item is expands. And if I'll click on two items there is will be two items with expanded view in my RecyclerView. I need to close others item's expandles view with item click. Only one item with expanded expandle view must be in recycler.

How do I can make this?

public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    holder.exp.collapse();
    holder.itemView.setOnClickListener(v -> {
        holder.exp.expand();
    });
picKit
  • 412
  • 1
  • 4
  • 14

1 Answers1

2

Save the Position of previously expanded position make a property in lists object like some boolean isOpen or something set it to false or true as required now on Click of a new row

list.get(prevPosition).setIsOpen(false);

then

notifyItemChanged(prevPosition);

make sure you have handled in your bindViewHolder something like this

if(list.get(postition).getIsOpen()==false){
//hide your expanded list
}
Rohit Sharma
  • 1,384
  • 12
  • 19