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.)
You can simply override
getCount()
method and test if adapter data array is superior than "DESIRED_MAX" then return "DESIRED_MAX" else just return the data array length or size (array/ArrayList)if you want it to keep inserting/scrolling, but only display X number of items, then I have a solution:
setVisibility
to VISIBLE for X items, and other is GONE.hope this helps
Inside your Recyclerview's adapter class;
One solution is to set width of each child programmatically,