Sandy
Sandy

Reputation: 6353

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?

Upvotes: 3

Views: 2186

Answers (1)

Micah Hainline
Micah Hainline

Reputation: 14437

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.

Upvotes: 4

Related Questions