T - The Java class that maps to the type of objects stored in the Firebase location.VH - The ViewHolder class that contains the Views in the layout that is shown for each object.public abstract class FirebaseRecyclerAdapter<T,VH extends android.support.v7.widget.RecyclerView.ViewHolder>
extends android.support.v7.widget.RecyclerView.Adapter<VH>
private static class ChatMessageViewHolder extends RecyclerView.ViewHolder { TextView messageText; TextView nameText; public ChatMessageViewHolder(View itemView) { super(itemView); nameText = (TextView)itemView.findViewById(android.R.id.text1); messageText = (TextView) itemView.findViewById(android.R.id.text2); } } FirebaseRecyclerAdapter<ChatMessage, ChatMessageViewHolder> adapter; ref = new Firebase("https://<yourapp>.firebaseio.com"); RecyclerView recycler = (RecyclerView) findViewById(R.id.messages_recycler); recycler.setHasFixedSize(true); recycler.setLayoutManager(new LinearLayoutManager(this)); adapter = new FirebaseRecyclerAdapter<ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) { public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage, int position) { chatMessageViewHolder.nameText.setText(chatMessage.getName()); chatMessageViewHolder.messageText.setText(chatMessage.getMessage()); } }; recycler.setAdapter(mAdapter);
| Modifier and Type | Field and Description |
|---|---|
protected int |
mModelLayout |
| Constructor and Description |
|---|
FirebaseRecyclerAdapter(Class<T> modelClass,
int modelLayout,
Class<VH> viewHolderClass,
com.firebase.client.Firebase ref) |
FirebaseRecyclerAdapter(Class<T> modelClass,
int modelLayout,
Class<VH> viewHolderClass,
com.firebase.client.Query ref) |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup() |
T |
getItem(int position) |
int |
getItemCount() |
long |
getItemId(int position) |
com.firebase.client.Firebase |
getRef(int position) |
void |
onBindViewHolder(VH viewHolder,
int position) |
VH |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType) |
protected T |
parseSnapshot(com.firebase.client.DataSnapshot snapshot)
This method parses the DataSnapshot into the requested type.
|
protected abstract void |
populateViewHolder(VH viewHolder,
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.
|
bindViewHolder, createViewHolder, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserverpublic FirebaseRecyclerAdapter(Class<T> modelClass, int modelLayout, Class<VH> viewHolderClass, com.firebase.client.Query ref)
modelClass - 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 item in the list. You will be responsible for populating an
instance of the corresponding view with the data from an instance of modelClass.viewHolderClass - The class that hold references to all sub-views in an instance modelLayout.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 FirebaseRecyclerAdapter(Class<T> modelClass, int modelLayout, Class<VH> viewHolderClass, com.firebase.client.Firebase ref)
modelClass - 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 item in the list. You will be responsible for populating an
instance of the corresponding view with the data from an instance of modelClass.viewHolderClass - The class that hold references to all sub-views in an instance modelLayout.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 getItemCount()
getItemCount in class android.support.v7.widget.RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>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 position)
getItemId in class android.support.v7.widget.RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>public VH onCreateViewHolder(android.view.ViewGroup parent, int viewType)
onCreateViewHolder in class android.support.v7.widget.RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>public void onBindViewHolder(VH viewHolder, int position)
onBindViewHolder in class android.support.v7.widget.RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>protected abstract void populateViewHolder(VH viewHolder, T model, int position)
Your implementation should populate the view using the data contained in the model.
viewHolder - The view to populatemodel - The object containing the data used to populate the viewposition - The position in the list of the view being populated