amir mobarakian
amir mobarakian

Reputation: 19

best method for loading more data from top of the listview android

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?

Upvotes: 0

Views: 1357

Answers (1)

SKG
SKG

Reputation: 366

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.

Upvotes: 2

Related Questions