解决方案是将ListView的高度与页脚的底部位置进行比较.
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3)
{
if(arg1 + arg2 == arg3) //If last row is visible. In this case, the last row is the footer.
{
if(footer != null) //footer is a variable referencing the footer view of the ListView. You need to initialize this onCreate
{
if(listView.getHeight() == footer.getBottom()) //Check if the whole footer is visible.
doThisMethod();
}
}
}
为了他人的兴趣,页脚基本上是一个View,我通过addFooterView添加到ListView. R.layout.footer是页脚的布局.下面是我如何初始化页脚并将其添加到ListView上的示例代码:
View footer; //This is a global variable.
....
//Inside onCreate or any method where you initialize your layouts
footer = getLayoutInflater().inflate(R.layout.footer, null);
listView.addFooterView(footer);