0

You can find my code here: How to correctly build table with data using onPostExecute and ListView

I need to do loading data from the server when my ListView is scroll to the bottom. I tried to looking for solution on Stackoverflow, but it is not helpful for me.

Also if it's not difficult i like to know how it's work for understand all.

Thank's to all

Community
  • 1
  • 1
user3323180
  • 43
  • 1
  • 7

2 Answers2

1

You have 2 solutions:

1) With OnScrollListener

You must have a class that extends ListView and implements OnScrollListener.

When you initialise the view, set it as the scroll listener : setOnScrollListener(this);

Implement the method onScroll. It's called when you scroll with the arguments firstVisibleItem, visibleItemCount and totalItemCount.

When firstVisibleItem+visibleItemCount==totalItemCount you reached the bottom of the list, you can call your AsyncTask again to load the next items.

2) With a custom adapter

In the method getView that you must overwrite, you have access to the position of the item being rendered, i.e. about to be visible on the screen.

Let's say you store your items in a List items you know when you reached the bottom of the list when position == items.size()-1. You can then call your AsyncTask.

Warning

Be careful with these 2 solutions, if all the items of the list fit in the screen, your AsyncTask may be called very often and for no reason. You must do the necessary checks for that before starting it.

Philippe A
  • 1,252
  • 9
  • 22
0

Use the Scroll state change listener in your program...I hope It will help you definitely ....

 listStudies.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (Logic Condition) {
                //Here also You can do your Logic here and then you can achieve your wishes.....
            }

        }
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
             if (Logic Condition) {
                //You just do your Logic here and then you can achieve your wishes.....
            }

        }
    });
Naveen Kumar Kuppan
  • 1,424
  • 1
  • 10
  • 12