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 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) { ((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 Activity |
mActivity |
protected int |
mLayout |
Constructor and Description |
---|
FirebaseListAdapter(Activity activity,
java.lang.Class<T> modelClass,
int modelLayout,
com.firebase.client.Firebase ref) |
FirebaseListAdapter(Activity activity,
java.lang.Class<T> modelClass,
int modelLayout,
com.firebase.client.Query ref) |
Modifier and Type | Method and Description |
---|---|
void |
cleanup() |
int |
getCount() |
T |
getItem(int i) |
long |
getItemId(int i) |
com.firebase.client.Firebase |
getRef(int position) |
View |
getView(int i,
View view,
ViewGroup viewGroup) |
protected abstract void |
populateView(View v,
T model)
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(Activity activity, java.lang.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(Activity activity, java.lang.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 i)
public com.firebase.client.Firebase getRef(int position)
public long getItemId(int i)
public View getView(int i, View view, ViewGroup viewGroup)
protected abstract void populateView(View v, T model)
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 view