找出 ListView 是否滚动到底部? [英] Find out if ListView is scrolled to the bottom?
本文介绍了找出 ListView 是否滚动到底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能否知道我的 ListView 是否滚动到底部?我的意思是最后一项是完全可见的.
Can I find out if my ListView is scrolled to the bottom? By that I mean that the last item is fully visible.
推荐答案
已编辑:
因为我一直在我的一个应用程序中研究这个特定主题,所以我可以为这个问题的未来读者写一个扩展的答案.
Since I have been investigating in this particular subject in one of my applications, I can write an extended answer for future readers of this question.
实现一个 OnScrollListener
,设置你的 ListView
的 onScrollListener
然后你应该能够正确处理事情.
Implement an OnScrollListener
, set your ListView
's onScrollListener
and then you should be able to handle things correctly.
例如:
private int preLast;
// Initialization stuff.
yourListView.setOnScrollListener(this);
// ... ... ...
@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount)
{
switch(lw.getId())
{
case R.id.your_list_id:
// Make your calculation stuff here. You have all your
// needed info from the parameters of this function.
// Sample calculation to determine if the last
// item is fully visible.
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount)
{
if(preLast!=lastItem)
{
//to avoid multiple calls for last item
Log.d("Last", "Last");
preLast = lastItem;
}
}
}
}
这篇关于找出 ListView 是否滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文