This project aims to provide a reusable listview widget with infinite scrolling capability for asynchronous data loading and displaying.
- Users scroll up to top or down to bottom of the listview widget to load more data
- Upon data loading finishes, listview widget automatically scrolls to the top/bottom, or stays where it was
- Self-explanatory demo code
Support Android API Level 8+
Manual:
- Download library from https://github.com/weixiao1984/Android-Infinite-Scroll-Listview/tree/master/library
- Import the library as an existing Android code into workspace
- In Properties for your project, add the imported project as a library
- Create an adapter which extends InfiniteScrollListAdapter
- Inside the adapter create an interface or abstract class so later actions in the view can be propagated to the customized adapter
public static abstract class NewPageListener {
public abstract void onScrollNext();
public abstract View getInfiniteScrollListView(int position, View convertView, ViewGroup parent);
}
@Override
protected void onScrollNext() {
if (newPageListener != null) {
newPageListener.onScrollNext();
}
}
@Override
public View getInfiniteScrollListView(int position, View convertView, ViewGroup parent) {
if (newPageListener != null) {
return newPageListener.getInfiniteScrollListView(position, convertView, parent);
}
return convertView;
}
- Loading Mode
- Either the list view scrolls to the top or the bottom
- Use setLoadingMode(LoadingMode loadingMode) to specify one of the following two loading modes
enum LoadingMode {SCROLL_TO_TOP, SCROLL_TO_BOTTOM};
- Stop Position
- When the data loading finishes, stop position determines weather the list view should automatically scroll up to the start of the list,
- scroll down to the end of the list, or remains where it was
- Use setStopPosition(StopPosition stopPosition) to specify one of the following three stop positions
enum StopPosition {START_OF_LIST, END_OF_LIST, REMAIN_UNCHANGED}
- Use AsyncTask or IntentService to process your data, as shown in the demo code https://github.com/weixiao1984/Android-Infinite-Scroll-Listview/tree/master/demo