简体   繁体   English

如何知道ListView的最后一项是专注于android?

[英]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.

相关问题 如何知道当前在ListView或GridView中聚焦的项目位置? - How to know the currently focused item position in ListView or GridView? 如何知道Android中何时将列表视图中的列表项聚焦(突出显示)? - How to know when a listitem in a listview is focused(highlighted) in Android? 如何在ListView - Android中为最后一项添加颜色? - How to add color to last item in ListView - Android? 按钮作为ListView Android中的最后一项 - Button as last item in ListView Android Android - Listview没有显示最后一项 - Android - Listview not showing the last item 有谁知道如何在Android listView中突出显示所选项目? - Does anyone know how to highlight a selected item in a Android listView? Android:ListView 中的 EditText 能否像列表项一样获得焦点? - Android: Can an EditText Within a ListView be Focused as Well as the List Item? 如何以可访问性为重点的当前项目Android - How to get accessibility focused current item Android Android-如何在Horizo​​ntal Listview的最后一项之后添加进度条? - Android - how to add progress bar after the last item of Horizontal Listview? 如何知道RecyclerView中的最后一项 - How to know last item in RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM