Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Endless scroll on ListView [closed]

I would like to implement endless scroll on an android ListView component, that will add new items to the bottom of the listview when scrolled to the last element in the list.

like image 949
ManiTeja Avatar asked Sep 25 '12 12:09

ManiTeja


2 Answers

implement the onscrolllistener()

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    this.currentFirstVisibleItem = firstVisibleItem;
    this.currentVisibleItemCount = visibleItemCount;
}

public void onScrollStateChanged(AbsListView view, int scrollState) {
    this.currentScrollState = scrollState;
    this.isScrollCompleted();
 }

private void isScrollCompleted() {
    if (this.currentVisibleItemCount > 0 && this.currentScrollState == SCROLL_STATE_IDLE) {
        /*** In this way I detect if there's been a scroll which has completed ***/
        /*** do the work for load more date! ***/
        if(!isLoading){
             isLoading = true;
             loadMoreDAta();
        }
    }
}

as you implement and add this listener to your listview this will detect for the end of listview as scroll position was at end of list just get more data. And during the loading data you need one flag to load data at once when the scroll position goes to end. So if data is loading and during that time you scroll up then scroll down then it will not get more data for dupplication.

like image 73
Pratik Avatar answered Nov 01 '22 22:11

Pratik


Try with OnScrollListener Just add the items to your ListView in your

public void onScroll(AbsListView view,
    int firstVisible, int visibleCount, int totalCount) {

    // Add the items

    }
}

And, setting your adapter.notifyDataSetChanged() will display the added items in your ListView Here i give you some example that how to integrate the onScrollListener with your ListView

  1. Android Endless List

  2. Endless Scrolling Listview

  3. Endless ListView

like image 25
Praveenkumar Avatar answered Nov 01 '22 23:11

Praveenkumar