I'm currently working on Xamarin android mobile application. There I have a requirement for displaying 50 list items using ArrrayAdapter in a 10-inch mobile screen.
When a mobile screen displays page with list items, It's showing by default 10 items at first. If I scroll further down it is showing items from 5 to 15. And if I scroll further it is showing 11 to 20.
At any given point of time, it is capable of displaying only 10 items.
How can I get the count(In ArrayAdapter GetView method) based on the screen size of the phone (in my case 10)?
Appreciate your help.
Thanks,
Veswanth
On Android the ListView has two properties that should help:
int start = listView.FirstVisiblePosition;
int end = listView.LastVisiblePosition;
So Subtract start from end and add 1 to get the total visible items, e.g.:
int numberOfVisibleItems = end - start + 1;
Note I did not test this, but it should work as long as you do this after the list is fully populated and displayed. Note that if even a sliver of a list item is in view, it will be counted.
EDIT: How to get the listView reference in GetView()
The ViewGroup parent
parameter of GetView(...)
should be the ListView
, so in GetView(...):
ListView listView = parent as ListView;
int start = listView.FirstVisiblePosition;
int end = listView.LastVisiblePosition;
int numberOfVisibleItems = end - start + 1;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments