T - The class type to use as a model for the data
contained in the children of the given Firebase locationpublic abstract class FirebaseIndexListAdapter<T> extends FirebaseListAdapter<T>
populateView, which will be given an
instance of your list item mLayout and an instance your class that holds your data.
Simply populate the view however you like and this class will handle updating the list as the data changes.
If your data is not indexed:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ListAdapter adapter = new FirebaseListAdapter(
this,
ChatMessage.class,
android.R.layout.two_line_list_item,
keyRef,
dataRef)
{
protected void populateView(View view, ChatMessage chatMessage, int position)
{
((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
}
};
listView.setListAdapter(adapter);
mActivity, mLayout| Constructor and Description |
|---|
FirebaseIndexListAdapter(android.app.Activity activity,
java.lang.Class<T> modelClass,
int modelLayout,
Query keyRef,
Query dataRef) |
cleanup, getCount, getItem, getItemId, getRef, getView, onCancelled, onChildChanged, onDataChanged, parseSnapshot, populateViewpublic FirebaseIndexListAdapter(android.app.Activity activity,
java.lang.Class<T> modelClass,
@LayoutRes
int modelLayout,
Query keyRef,
Query dataRef)
activity - The activity containing the ListViewmodelClass - Firebase will marshall the data at a location into
an instance of a class that you providemodelLayout - This is the layout used to represent a single list item.
You will be responsible for populating an instance of the corresponding
view with the data from an instance of modelClass.keyRef - The Firebase location containing the list of keys to be found in dataRef.
Can also be a slice of a location, using some
combination of limit(), startAt(), and endAt().dataRef - The Firebase location to watch for data changes.
Each key key found in keyRef's location represents
a list item in the ListView.