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.
Asked
Active
Viewed 1.6k times
3 Answers
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