Finding the last line of a scroll list - Android

I want to load data into a listview when it displays the last row. I am writing a scroll for a list.

Now, how do you determine if listview is displaying the last row?

Can anyone help me out?

+4
source share
4 answers
lv.setOnScrollListener(new OnScrollListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Check if the last view is visible if (++firstVisibleItem + visibleItemCount > totalItemCount) { // if so, download more content } } } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO Auto-generated method stub } }); 
+5
source

You can use the Amazing ListView to automatically load the following pages (i.e., "Loading ..." on the last item).

ListView with "Loading ..." animation at the bottom

In accordance with the documentation, the following methods are implemented:

  • onNextPageRequested Called when the user scrolls the list until the loading indicator appears. This is called a UI thread, so if you have some network requests, make sure you do this in the background. page number is also indicated.

By default, you are counted on the last page and you will not see the message "Loading ..." at the bottom of the list. You need to control if there are more pages to display.

  • notifyMayHaveMorePages to indicate that we still have more data, so the message "Loading ..." will be displayed.
  • notifyNoMorePages to indicate that we have downloaded all the data, so you no longer need to display the message "Loading ...".
  • nextPage to increase the page number. Do this by adding new data to your adapter.
  • resetPage to reset page number to 1 (or the value specified by setInitialPage ).

So what you need to do is get extra data when onNextPageRequested is onNextPageRequested . And call nextPage when adding new data to your adapter.

0
source

Try this in list view .. it does a great job with me ..

 ((ScrollView) findViewById(R.id.scrollDowns)).fullScroll(View.FOCUS_DOWN); 
0
source

The aforementioned slezadav implementation may lead to errors under boundary conditions. The sum of the first visible element and the elements on the page can be 1 count more or less than expected. I used the same until I switched to a new method. What I did was set by the listener in the Adapter of listview and in the getview check if (position == totalItemCount of the elements in the array will be displayed), if so, I call my listener from the adapter and the listener will pull more data from the api. Pretty simple

0
source

All Articles