How Can I Implement Paging In Listview In Android?
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 listv
Solution 1:
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...
Solution 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
Solution 3:
Check out cwac endless adapter to implement paging.
Post a Comment for "How Can I Implement Paging In Listview In Android?"