How do I know if the last row of a ListView is fully displayed?

I know how to check if the last row of a ListView is visible. However, visibility does not guarantee that the string is fully displayed. How to check if the last line is displayed completely?

+4
source share
2 answers

The solution is to compare the height of the ListView at the bottom 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(); } } } 

In the interest of others, the footer is basically a View , which I added to the ListView via addFooterView . R.layout.footer is the layout for the footer. The following is a sample code of how I initialized the footer and added it to 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); 
+5
source

I would try something like (not tested):

 if (listView.getScrollY() == listView.getMaxScrollAmount()) { // ... } 
0
source

Source: https://habr.com/ru/post/1396579/


All Articles