There is a GridLayoutManager and I want to click on any item to hide everything except the horizontal line in which the item is located. It should look like this.

enter image description here enter image description here

Any ideas on how to do this?

  • You can transfer to what adapter the click was made, and call notifyDataSetChanged() , and when redrawing, check if the item is in the right row, then draw it as usual, and if not, just transparent. - Vladyslav Matviienko
  • @metalurgus and how to implement it correctly, I can’t imagine how it should work in code. - Satanist Devilov
  • what exactly? What specifically do not know how to implement? How to find out which line was clicked? How to transfer time to the adapter number? How to find the line number of the currently created list item? How to make a list item transparent? More specifically, describe the problem, nobody will provide you with the complete ready-made code here. - Vladyslav Matviienko
  • @metalurgus How can I find the line number in which item was clicked. And how to hide all lines except this one. - Satanist Devilov

1 answer 1

How can I find the line number in which item was clicked

GridLayoutManager takes the number of columns. Depending on the number of columns and the position of the element, you can calculate which line it is in:

 int row = position / columnCount; 

And how to hide all lines except this one.

In the onBindViewHolder() adapter method, calculate the line number in which this item is located.
Then compare it with the line number of the clicked item, and if they do not match, then hide all the View in the item.