0

There was some method for loading more data when scroll to the bottom.but I need a method for load data by scrolling to the top of the list in android. like whats up and another chat application. can you help me?

leppie
  • 115,091
  • 17
  • 196
  • 297

1 Answers1

2

Below logic will work for loading more data when you scroll to the top of the listview.

listview.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            currentScrollState = scrollState;
            if (currentVisibleItemCount > 0 && currentScrollState == SCROLL_STATE_IDLE) {
                if (currentFirstVisibleItem == 0) {

                    // getMessages(); //write what you want to do when you scroll up to the end of listview.

                }
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,int totalItemCount) {
            currentFirstVisibleItem = firstVisibleItem;
            currentVisibleItemCount = visibleItemCount;
            currentTotalItemCount = totalItemCount;
        }
    });

Hope this helps.

SKG
  • 346
  • 4
  • 11