2

Basically I'm trying to skip certain items of recyclerview by making that view's visibility GONE by help of this SOanswer .It's working like a charm for the linear_recyclerview without showing the blank space after skipping items but in case of grid_recyclerview it's showing the vacant space . Can anyone please help me to resolve this issue.

Code:

if(position==0){
holder.itemView.setVisibility(View.GONE); 
holder.itemView.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
 } 
Srinivas Nahak
  • 1,846
  • 4
  • 20
  • 45
  • 1
    Why not just remove the items from your adapter's data set? – Ben P. Mar 25 '18 at 23:27
  • 1
    Using visibility to show/hide item rows is really bad, you should be filtering your dataset and removing/adding rows. What do you think happens using this logic when you try and dynamically add items into your dataset .. nothing good! – Mark Mar 25 '18 at 23:29

1 Answers1

6

I think it would be better to remove the unwanted items from the data source and then just show all the other items. It's much simpler and more effective. This way, you will never get a blank space, while with marking an itemView as GONE may still show blank space in some specific cases.

deluxe1
  • 737
  • 4
  • 15
  • yeah! you are right. making itemView holder gone will show white screen. but covering all cases will not show white screen as well – Ashu Kumar Mar 26 '18 at 02:41
  • Although your suggestion is great but it gives **indexOutOfBoundException** a lot of times that's why I was trying to make the view Gone . But it would be a great help if you could suggest some ideas how to remove item at particular position efficiently. – Srinivas Nahak Mar 26 '18 at 09:05
  • Can you please post the code you are currently using which causes the indexOutOfBoundsExeption? – deluxe1 Mar 26 '18 at 11:28