T - The class type to use as a model for the data contained in the children of the given Firebase locationpublic abstract class FirebaseListAdapter<T>
extends android.widget.BaseAdapter
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.
Firebase ref = new Firebase("https://<yourapp>.firebaseio.com"); ListAdapter adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, mRef) { 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);
| Modifier and Type | Field and Description |
|---|---|
protected android.app.Activity |
mActivity |
protected int |
mLayout |
| Constructor and Description |
|---|
FirebaseListAdapter(android.app.Activity activity,
Class<T> modelClass,
int modelLayout,
com.firebase.client.Firebase ref) |
FirebaseListAdapter(android.app.Activity activity,
Class<T> modelClass,
int modelLayout,
com.firebase.client.Query ref) |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup() |
int |
getCount() |
T |
getItem(int position) |
long |
getItemId(int i) |
com.firebase.client.Firebase |
getRef(int position) |
android.view.View |
getView(int position,
android.view.View view,
android.view.ViewGroup viewGroup) |
protected T |
parseSnapshot(com.firebase.client.DataSnapshot snapshot)
This method parses the DataSnapshot into the requested type.
|
protected abstract void |
populateView(android.view.View v,
T model,
int position)
Each time the data at the given Firebase location changes, this method will be called for each item that needs
to be displayed.
|
public FirebaseListAdapter(android.app.Activity activity,
Class<T> modelClass,
int modelLayout,
com.firebase.client.Query ref)
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.ref - The Firebase location to watch for data changes. Can also be a slice of a location, using some
combination of limit(), startAt(), and endAt(),public FirebaseListAdapter(android.app.Activity activity,
Class<T> modelClass,
int modelLayout,
com.firebase.client.Firebase ref)
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.ref - The Firebase location to watch for data changes. Can also be a slice of a location, using some
combination of limit(), startAt(), and endAt(),public void cleanup()
public int getCount()
public T getItem(int position)
protected T parseSnapshot(com.firebase.client.DataSnapshot snapshot)
snapshot - the DataSnapshot to extract the model frompublic com.firebase.client.Firebase getRef(int position)
public long getItemId(int i)
public android.view.View getView(int position,
android.view.View view,
android.view.ViewGroup viewGroup)
protected abstract void populateView(android.view.View v,
T model,
int position)
Your implementation should populate the view using the data contained in the model.
v - The view to populatemodel - The object containing the data used to populate the viewposition - The position in the list of the view being populated