[英]How to know last item of ListView is focused in android?
I have a listview which contains N no. 我有一个包含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? 方法,但不知道我怎么才能知道最后一行是关注的?
If by focused you mean selected (scrolled down by the keyboard, has the selection rectangle around it) then just use setOnItemSelectedListener. 如果通过聚焦意味着选择(通过键盘向下滚动,周围有选择矩形),那么只需使用setOnItemSelectedListener。 The int argument is the position, compare that to the number of items in your list and you're golden.
int参数是位置,将其与列表中的项目数进行比较,您就是黄金。
If by focused you mean visible, then use setOnScrollListener, which has this method: 如果通过聚焦意味着可见,则使用setOnScrollListener,它具有以下方法:
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. 只需先显示+ visible即可显示最后一项,您可以将其与总数进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.