Reputation: 6819
I know how to check if the last row of the ListView is visible. However, being visible doesn't guarantee that the row is displayed fully. How can I check if the last row is displayed fully?
Upvotes: 4
Views: 2258
Reputation: 6819
The solution is to compare the height of the ListView to the bottom position of the footer.
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();
}
}
}
For the interest of others, the footer is basically a View
which I added to the ListView
via the addFooterView
. R.layout.footer
is the layout for the footer. Below is a sample code on how I initialize the footer and added it on the 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);
Upvotes: 5
Reputation: 89576
I'd try something like (not tested):
if (listView.getScrollY() == listView.getMaxScrollAmount()) {
// ...
}
Upvotes: 0