In my viewHolder, using holder.itemView retrieves the row's contents, so when I use setVisibility() on it, it only hides the contents of the row. How can I hide the whole row instead, by getting a reference to the row's parent view or otherwise?
Asked
Active
Viewed 1,903 times
0
-
`list.remove(position)` followed by `adapter.notifyItemRemoved(position)` – Santanu Sur Feb 21 '20 at 10:51
-
That could work, but this view is directly casted at position == 0 of the recyclerView, hence it is not saved in any list. How would I be able to make it visible/add it back to the recyclerView again afterwards? – George Feb 21 '20 at 10:55
-
The parent view is the `RecyclerView`, you'd have to add your own parent view to do this, and then it'd just be the `itemView` – Ryan M Feb 21 '20 at 10:56
-
1Also there are a bunch of answers here: https://stackoverflow.com/questions/27574805/hiding-views-in-recyclerview – Ryan M Feb 21 '20 at 11:00
-
@RyanMentley thank you, the last link was more than helpful, I used LayoutParams instead to set the visibility AND margin of the row I wanted to show/hide during searching! – George Feb 21 '20 at 11:24
1 Answers
0
You can hide whole content using Viewholder's rootview. This will hide your whole row
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view =
LayoutInflater.from(parent.getContext(),
R.layout.row_select_card, parent, false);
return new MyViewHolder(view);
}
private class MyViewHolder extends RecyclerView.ViewHolder {
private View view;
private MyViewHolder(View itemView) {
super(itemView);
itemview.setVisibility(View.GONE);
}
}

Jignesh Mayani
- 6,937
- 1
- 20
- 36
-
Hm okay, it is possible to check for a boolean in my ViewHolder class though (e.g. if isSearchMode then hide that single itemView, else show that single itemView)? – George Feb 21 '20 at 11:33
-
you can show or hide itemview in MyViewHolder class depend on your condition – Jignesh Mayani Feb 21 '20 at 11:46