1

I am working on 1 functionality in which If selects Gender from one Recyclerview itemtype, The other recyclerview itemtype should be gone or set visible according to the flag in model object. Currently I used below approach:

if (genderSelected != genderPreference) {
      holder.itemView.visibility = View.GONE
} else {
      holder.itemView.visibility = View.VISIBLE
}

With this, the item is Going and again visible leaving white space behind on Gone.

I want it to get removed temporarily without any space.

Thanks in advance.

Deep Patel
  • 2,584
  • 2
  • 15
  • 28
Siraj Sumra
  • 934
  • 1
  • 11
  • 28
  • your want `recyclerView` item to be gone ? – Abdul Kawee Feb 26 '18 at 12:16
  • Yes temporarily, but again if user changes gender then it should be visible again – Siraj Sumra Feb 26 '18 at 12:20
  • Hello @SirajSumra, Can you please share your code here? – Chintak Patel Feb 26 '18 at 12:22
  • 1
    Why are you showing/hiding rows in your recyclerview. Just show the relevant views for the data provided in your recyclerview? When the data changes update the recyclerview to show your updated dataset. Filter the dataset, don't have view logic. – Mark Feb 26 '18 at 12:28
  • Possible duplicate of [How to hide an item from Recycler View on a particular condition?](https://stackoverflow.com/questions/41223413/how-to-hide-an-item-from-recycler-view-on-a-particular-condition) – MSpeed Feb 26 '18 at 13:41

1 Answers1

1

Modifying visibility from my understanding will leave a white space no matter what you do because the recyclerview is using essentially a prebuilt list and creates that space off of that. Now to accomplish this what I would do is on that gender click repopulate the recyclerview with new data that is queried to meet your needs. Similar to if you wanted a search bar that updated with every letter added. You update your recyclerview after modifying the data not the view itself.

Vahalaru
  • 380
  • 4
  • 15
  • I can’t upvote yet but mark keen nailed it in the comments. Your doing it backwards. The view even if removed is still taking up space in that position of the recyclerview. Update the data, they get new positions, you accomplish your wildest dreams. – Vahalaru Mar 02 '18 at 02:51