How can I limit the number of items displayed by the RecyclerView ?
I can limit the amount inserted it if I override getChildCount
, but that causes it to only insert that number and then stop. I want it to keep inserting/scrolling, but only display X number of items.
(Note: The height of each item can differ, so it's important that the limit is based on quantity rather than some hard coded value.)
Inside your Recyclerview's adapter class;
private final int limit = 10;
@Override
public int getItemCount() {
if(ad_list.size() > limit){
return limit;
}
else
{
return ad_list.size();
}
}
In your Adapter, just set a limit,
@Override
public int getItemCount() {
int limit = 5;
return Math.min(diseasesList.size(), limit);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With