public class PartialLoadingAdapter
extends android.widget.BaseAdapter
implements android.widget.Filterable, android.widget.WrapperListAdapter
Adapter for loading large cursors backed by RESTful services with a local cache in a database. This adapter is responsible for displaying "loading" items in the end of already loaded items in case when there is at least one more portion of unfetched data and for calling for that unfetched portion of data either.
Adapter does NOT provide any functionality for loading data itself, calling supplied listener PartialLoadingListener to start a loading process. loadNextPortionOfData method is called on the background thread by default unless you change this by calling setLoadNextPortionOnBackgroundThread(false).
Adapter always tries to load one more portion of data while user is looking through the end of the already shown portion. The threshold of "the end" can be configured through the setCursorPositionLoadingThreshold method. The default value is 15, which means that in case when cursor's length is 50 then the loading starts when the user goes further than 50 - 15 = 35 records. Note that loading doesn't start immediately. It is required that the threshold is crossed 3 times at least. It prevents us from reacting to "false" views when a ListView triggers adapter's getView method to determine it's length for example.
| Modifier and Type | Class and Description |
|---|---|
static interface |
PartialLoadingAdapter.PartialLoadingListener |
| Constructor and Description |
|---|
PartialLoadingAdapter(android.support.v4.widget.CursorAdapter cursorAdapter,
PartialLoadingAdapter.PartialLoadingListener listener,
android.content.Context context,
int loadingViewResId) |
PartialLoadingAdapter(android.support.v4.widget.CursorAdapter cursorAdapter,
PartialLoadingAdapter.PartialLoadingListener listener,
android.view.View loadingView) |
| Modifier and Type | Method and Description |
|---|---|
int |
getCount() |
int |
getCursorPositionLoadingThreshold() |
android.widget.Filter |
getFilter() |
Object |
getItem(int position) |
long |
getItemId(int position) |
android.view.View |
getView(int position,
android.view.View convertView,
android.view.ViewGroup parent) |
android.widget.ListAdapter |
getWrappedAdapter() |
boolean |
isLoadNextPortionOnBackgroundThread() |
void |
setCursorPositionLoadingThreshold(int cursorPositionLoadingThreshold) |
void |
setLoadNextPortionOnBackgroundThread(boolean loadNextPortionOnBackgroundThread) |
android.database.Cursor |
swapCursor(android.database.Cursor newCursor) |
areAllItemsEnabled, getDropDownView, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetChanged, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserverpublic PartialLoadingAdapter(android.support.v4.widget.CursorAdapter cursorAdapter,
PartialLoadingAdapter.PartialLoadingListener listener,
android.content.Context context,
int loadingViewResId)
public PartialLoadingAdapter(android.support.v4.widget.CursorAdapter cursorAdapter,
PartialLoadingAdapter.PartialLoadingListener listener,
android.view.View loadingView)
public int getCursorPositionLoadingThreshold()
public void setCursorPositionLoadingThreshold(int cursorPositionLoadingThreshold)
public boolean isLoadNextPortionOnBackgroundThread()
public void setLoadNextPortionOnBackgroundThread(boolean loadNextPortionOnBackgroundThread)
public android.database.Cursor swapCursor(android.database.Cursor newCursor)
public android.widget.ListAdapter getWrappedAdapter()
getWrappedAdapter in interface android.widget.WrapperListAdapterpublic int getCount()
getCount in interface android.widget.Adapterpublic Object getItem(int position)
getItem in interface android.widget.Adapterpublic long getItemId(int position)
getItemId in interface android.widget.Adapterpublic android.view.View getView(int position,
android.view.View convertView,
android.view.ViewGroup parent)
getView in interface android.widget.Adapterpublic android.widget.Filter getFilter()
getFilter in interface android.widget.FilterableCopyright © 2015. All Rights Reserved.