Skip to content

Latest commit

 

History

History
71 lines (55 loc) · 2.76 KB

File metadata and controls

71 lines (55 loc) · 2.76 KB

Android-Infinite-Scroll-Listview

This project aims to provide a reusable listview widget with infinite scrolling capability for asynchronous data loading and displaying.

Screenshot-1 Screenshot-2 Screenshot-3 Screenshot-4

Features

  • 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+

Quick Setup

1. Include library

Manual:

2. Adapter class

  • 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;
}

3. Activity class

  1. 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};
  1. 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}
  1. 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