public class ParseQueryAdapter<T extends ParseObject> extends BaseAdapter
This class is highly configurable, but also intended to be easy to get started with. See below
for an example of using a ParseQueryAdapter inside an Activity's onCreate:
final ParseQueryAdapter adapter = new ParseQueryAdapter(this, "TestObject");
adapter.setTextKey("name");
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
Below, an example showing off the level of configuration available with this class:
// Instantiate a QueryFactory to define the ParseQuery to be used for fetching items in this
// Adapter.
ParseQueryAdapter.QueryFactory<ParseObject> factory =
new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Customer");
query.whereEqualTo("activated", true);
query.orderByDescending("moneySpent");
return query;
}
};
// Pass the factory into the ParseQueryAdapter's constructor.
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(this, factory);
adapter.setTextKey("name");
// Perhaps set a callback to be fired upon successful loading of a new set of ParseObjects.
adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
public void onLoading() {
// Trigger any "loading" UI
}
public void onLoaded(List<ParseObject> objects, ParseException e) {
// Execute any post-loading logic, hide "loading" UI
}
});
// Attach it to your ListView, as in the example above
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
| Modifier and Type | Class and Description |
|---|---|
static interface |
ParseQueryAdapter.OnQueryLoadListener<T extends ParseObject>
Implement with logic that is called before and after objects are fetched from Parse by the
adapter.
|
static interface |
ParseQueryAdapter.QueryFactory<T extends ParseObject>
Implement to construct your own custom
ParseQuery for fetching objects. |
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION| Constructor and Description |
|---|
ParseQueryAdapter(Context context,
Class<? extends ParseObject> clazz)
Constructs a ParseQueryAdapter.
|
ParseQueryAdapter(Context context,
Class<? extends ParseObject> clazz,
int itemViewResource)
Constructs a ParseQueryAdapter.
|
ParseQueryAdapter(Context context,
ParseQueryAdapter.QueryFactory<T> queryFactory)
Constructs a ParseQueryAdapter.
|
ParseQueryAdapter(Context context,
ParseQueryAdapter.QueryFactory<T> queryFactory,
int itemViewResource)
Constructs a ParseQueryAdapter.
|
ParseQueryAdapter(Context context,
String className)
Constructs a ParseQueryAdapter.
|
ParseQueryAdapter(Context context,
String className,
int itemViewResource)
Constructs a ParseQueryAdapter.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addOnQueryLoadListener(ParseQueryAdapter.OnQueryLoadListener<T> listener) |
void |
clear()
Remove all elements from the list.
|
Context |
getContext()
Return the context provided by the
Activity utilizing this ParseQueryAdapter. |
int |
getCount()
Overrides
Adapter's ParseQueryAdapter.getCount() method to return the number of cells to
display. |
T |
getItem(int index) |
long |
getItemId(int position) |
View |
getItemView(T object,
View v,
ViewGroup parent)
Override this method to customize each cell given a
ParseObject. |
int |
getItemViewType(int position) |
View |
getNextPageView(View v,
ViewGroup parent)
Override this method to customize the "Load Next Page" cell, visible when pagination is turned
on and there may be more results to display.
|
int |
getObjectsPerPage() |
View |
getView(int position,
View convertView,
ViewGroup parent)
The base class,
Adapter, defines a getView method intended to display data at
the specified position in the data set. |
int |
getViewTypeCount() |
void |
loadNextPage()
Loads the next page of objects, appends to table, and notifies the UI that the model has
changed.
|
void |
loadObjects()
Clears the table and loads the first page of objects asynchronously.
|
void |
registerDataSetObserver(DataSetObserver observer) |
void |
removeOnQueryLoadListener(ParseQueryAdapter.OnQueryLoadListener<T> listener) |
void |
setAutoload(boolean autoload)
Enable or disable the automatic loading of results upon attachment to an
AdapterView. |
void |
setImageKey(String imageKey) |
void |
setObjectsPerPage(int objectsPerPage) |
protected void |
setPageOnQuery(int page,
ParseQuery<T> query)
Override this method to manually paginate the provided
ParseQuery. |
void |
setPaginationEnabled(boolean paginationEnabled)
Enable or disable pagination of results.
|
void |
setPlaceholder(Drawable placeholder)
Sets a placeholder image to be used when fetching data for each item in the
AdapterView
. |
void |
setTextKey(String textKey) |
void |
unregisterDataSetObserver(DataSetObserver observer) |
areAllItemsEnabled, getDropDownView, hasStableIds, isEmpty, isEnabled, notifyDataSetChanged, notifyDataSetInvalidatedpublic ParseQueryAdapter(Context context, Class<? extends ParseObject> clazz)
context - The activity utilizing this adapter.clazz - The ParseObject subclass type to fetch and display.public ParseQueryAdapter(Context context, String className)
context - The activity utilizing this adapter.className - The name of the Parse class of ParseObjects to display.public ParseQueryAdapter(Context context, Class<? extends ParseObject> clazz, int itemViewResource)
context - The activity utilizing this adapter.clazz - The ParseObject subclass type to fetch and display.itemViewResource - A resource id that represents the layout for an item in the AdapterView.public ParseQueryAdapter(Context context, String className, int itemViewResource)
context - The activity utilizing this adapter.className - The name of the Parse class of ParseObjects to display.itemViewResource - A resource id that represents the layout for an item in the AdapterView.public ParseQueryAdapter(Context context, ParseQueryAdapter.QueryFactory<T> queryFactory)
ParseQuery to be used when fetching items from Parse.context - The activity utilizing this adapter.queryFactory - A ParseQueryAdapter.QueryFactory to build a ParseQuery for fetching objects.public ParseQueryAdapter(Context context, ParseQueryAdapter.QueryFactory<T> queryFactory, int itemViewResource)
ParseQuery to be used when fetching items from Parse.context - The activity utilizing this adapter.queryFactory - A ParseQueryAdapter.QueryFactory to build a ParseQuery for fetching objects.itemViewResource - A resource id that represents the layout for an item in the AdapterView.public Context getContext()
Activity utilizing this ParseQueryAdapter.public T getItem(int index)
public long getItemId(int position)
public int getItemViewType(int position)
getItemViewType in interface AdaptergetItemViewType in class BaseAdapterpublic int getViewTypeCount()
getViewTypeCount in interface AdaptergetViewTypeCount in class BaseAdapterpublic void registerDataSetObserver(DataSetObserver observer)
registerDataSetObserver in interface AdapterregisterDataSetObserver in class BaseAdapterpublic void unregisterDataSetObserver(DataSetObserver observer)
unregisterDataSetObserver in interface AdapterunregisterDataSetObserver in class BaseAdapterpublic void clear()
public void loadObjects()
Adapter is attached to an AdapterView.
loadObjects() should only need to be called if ParseQueryAdapter.setAutoload(boolean) is set to
false.public void loadNextPage()
public int getCount()
Adapter's ParseQueryAdapter.getCount() method to return the number of cells to
display. If pagination is turned on, this count will include an extra +1 count for the
pagination cell row.public View getItemView(T object, View v, ViewGroup parent)
ParseObject.
If a view is not provided, a default view will be created based upon
android.R.layout.activity_list_item.
This method expects a TextView with id android.R.id.text1 in your object views.
If ParseQueryAdapter.setImageKey(String) was used, this method also expects an ImageView with id
android.R.id.icon.
This method displays the text value specified by the text key (set via
ParseQueryAdapter.setTextKey(String)) and an image (described by a ParseFile, under the key set
via ParseQueryAdapter.setImageKey(String)) if applicable. If the text key is not set, the value for
ParseObject.getObjectId() will be displayed instead.object - The ParseObject associated with this item.v - The View associated with this row. This view, if non-null, is being recycled
and intended to be used for displaying this item.parent - The parent that this view will eventually be attached topublic View getNextPageView(View v, ViewGroup parent)
TextView with id android.R.id.text1.v - The view object associated with this row + type (a "Next Page" view, instead of an
"Item" view).parent - The parent that this view will eventually be attached topublic final View getView(int position, View convertView, ViewGroup parent)
Adapter, defines a getView method intended to display data at
the specified position in the data set. We override it here in order to toggle between
ParseQueryAdapter.getNextPageView(View, ViewGroup) and
ParseQueryAdapter.getItemView(ParseObject, View, ViewGroup) depending on the value of
ParseQueryAdapter.getItemViewType(int).protected void setPageOnQuery(int page,
ParseQuery<T> query)
ParseQuery. By default, this
method will set the limit value to ParseQueryAdapter.getObjectsPerPage() and the skip
value to ParseQueryAdapter.getObjectsPerPage() * page.
Overriding this method will not be necessary, in most cases.
page - the page number of results to fetch from Parse.query - the ParseQuery used to fetch items from Parse. This query will be mutated and
used in its mutated form.public void setTextKey(String textKey)
public void setImageKey(String imageKey)
public void setObjectsPerPage(int objectsPerPage)
public int getObjectsPerPage()
public void setPaginationEnabled(boolean paginationEnabled)
paginationEnabled - Defaults to true.public void setPlaceholder(Drawable placeholder)
AdapterView
. Will not be used if ParseQueryAdapter.setImageKey(String) was not used to define which images to
display.placeholder - A Drawable to be displayed while the remote image data is being fetched. This
value can be null, and ImageViews in this AdapterView will simply be blank
while data is being fetched.public void setAutoload(boolean autoload)
AdapterView.
Defaults to true.autoload - Defaults to true.public void addOnQueryLoadListener(ParseQueryAdapter.OnQueryLoadListener<T> listener)
public void removeOnQueryLoadListener(ParseQueryAdapter.OnQueryLoadListener<T> listener)