Reputation: 333
I want to hide View in items of RecyclerView .
I have if/else
statement in BindViewHolder as shown:
if (position == list.size() - 1)
{
holder.divider.setVisibility(View.Gone)
}
It was working initially and my View got disappeared but when I scroll back, some View also got disappeared, and I have no idea to solve this , i tried holder.getAdapterposition
but still happening the same . It will be very grateful if someone can help me.
Upvotes: 1
Views: 2884
Reputation: 1385
Every time you want to use if
statement inside onBindViewHolder
, always put else with it. RecyclerView reuse views, so it should know if anything special regarding specific rows as well as normal formatting for normal rows.
if (position == list.size() - 1){
holder.divider.setVisibility(View.GONE);
}else{
holder.divider.setVisibility(View.VISIBLE);
}
Upvotes: 5