Issue
I have a Recycler View that is showing a list of elements. My list has 100 elements and after building the list and load in recycler I need to know how many elements I can see on my screen.
Follow the image below :
I need to know the number of elements that I can see in the list. In that example, following the number of Add Buttons as a reference, They are 4 elements.
Solution
you can get the on-screen item count as follow
RecyclerView recyclerView = findViewById(R.id.recyclerview);
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager);
//get on-screen items count.
int currentItems = layoutManager.getChildCount();
//get total items count.
int totalItems = layoutManager.getItemCount();
//get scroll-out items count
int scrollOutItems = layoutManager.findFirstVisibleItemPosition();
Answered By - Shivam Jamaiwar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.