How to listen to the last element of ListView?

There are 10 elements allowed. How to catch that moment when the 10th element is on the screen?

Or when the listview has reached the end?

  • start by analyzing habrahabr.ru/post/135226 or explain why you need to know that the element is displayed. - KoVadim
  • @ KoVadim, Pull-To-Refresh This is not the case. I need to dynamically add elements like in VK. Scroll down they are loaded and added - Andro
  • 2
    That's what you need to write in the question! - KoVadim
  • I will consider for the future - Andro

1 answer 1

ListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisible, int visibleCount, int totalItem) { if(firstVisible + visibleCount == totalItem){ //то что нужно тебе } } }); 

If you need to do data loading in a listView, for example, 10 elements Boolean isLoad = false , then you can do this: create Boolean isLoad = false , and add if((firstVisible + visibleCount == totalCount) && (isLoad) && (totalCount>0)) to the condition , if the condition is met, you вызываешь метод для получения следующих 10 элементов списка (либо как тебе удобно) и делаешь isLoad = false; , and after adding the following elements you do isLoad = true

  • Same several times is caused ?. Once 4-20. Maybe there is another way? - Andro
  • And if you put in the footer button. And do so to listen to this button. Then when it is visible on the screen. Then and do what you need and will be called only 1 time - Andro
  • changed the answer. - Nikotin N