Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know last item of ListView is focused in android?

I have a listview which contains N no. of items. When user scroll down the list and reached to the last. I want to know when user is in the last row of the list. How to know this? I can use

onFocus

method, but don't know how can i come to know that last row is focused?

like image 928
Sandy Avatar asked Jan 29 '26 05:01

Sandy


1 Answers

If by focused you mean selected (scrolled down by the keyboard, has the selection rectangle around it) then just use setOnItemSelectedListener. The int argument is the position, compare that to the number of items in your list and you're golden.

If by focused you mean visible, then use setOnScrollListener, which has this method:

onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)

Just first + visible will get the last item shown, which you can compare to the total.

like image 52
Micah Hainline Avatar answered Jan 31 '26 19:01

Micah Hainline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!