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 FirebaseRecyclerViewAdapter<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); } } FirebaseRecyclerViewAdapter<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 FirebaseRecyclerViewAdapter<ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) { public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) { 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 |
---|
FirebaseRecyclerViewAdapter(java.lang.Class<T> modelClass,
int modelLayout,
java.lang.Class<VH> viewHolderClass,
com.firebase.client.Firebase ref) |
FirebaseRecyclerViewAdapter(java.lang.Class<T> modelClass,
int modelLayout,
java.lang.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 i) |
VH |
onCreateViewHolder(ViewGroup parent,
int viewType) |
abstract void |
populateViewHolder(VH viewHolder,
T model) |
bindViewHolder, createViewHolder, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
public FirebaseRecyclerViewAdapter(java.lang.Class<T> modelClass, int modelLayout, java.lang.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 FirebaseRecyclerViewAdapter(java.lang.Class<T> modelClass, int modelLayout, java.lang.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)
public 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(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 i)
onBindViewHolder
in class android.support.v7.widget.RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>