1

I want to make an application in which I have 100 uri of images that are saved in database..Now I want that whole data will not be fetched from database only to display in listview. I want that I get data only up to current view screen of list so next item I scroll the list than next data items will be fetched so application will not be slow for display data in listview.

thumbtackthief
  • 6,093
  • 10
  • 41
  • 87
user1371486
  • 39
  • 1
  • 1
  • 7

3 Answers3

3

lengthy list-view doesn't make your scrolling slow just fetch all 100 uri in single occurence and fill in adapter; it will work properly...

Chintan Raghwani
  • 3,370
  • 4
  • 22
  • 33
2

There is a scroll listener below:

class EndlessScrollListener implements OnScrollListener{
    private static final String TAG = "CacheToDBActivity.EndlessScrollListener";
    private boolean loading = true;

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {
        if (!(loading) && (totalItemCount - visibleItemCount) <= (firstVisibleItem)) {
            Log.d(TAG, "Load Next Page!");
            loading = true;
        }
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {}

    public boolean isLoading() {
        return loading;
    }

    public void setLoading(boolean loading) {
        this.loading = loading;
    }

}

You can instantiate an EndlessScrollListener and set your listview's onScrollListener like:

yourListView.setOnScrollListener(endlessScrollListener);

And above the endlessscrollListener's Log.d(TAG, "Load Next Page!"); line you can fetch items from database, and add them to your adapter.

After calling notifyDataSetChanged(); your items will be visible in the list

Hope this helps

Murat Nafiz
  • 1,438
  • 17
  • 28
1

Check out cwac endless adapter to implement paging.

Tarun
  • 13,727
  • 8
  • 42
  • 57