-
- All Implemented Interfaces:
-
androidx.lifecycle.LifecycleObserver,com.firebase.ui.common.BaseChangeEventListener,com.firebase.ui.database.ChangeEventListener,com.firebase.ui.database.FirebaseAdapter
public abstract class FirebaseRecyclerAdapter<T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> implements FirebaseAdapter<T>
This class is a generic way of backing a RecyclerView with a Firebase location. It handles all of the child events at the given Firebase location and marshals received data into the given class type.
See the READMEfor an in-depth tutorial on how to set up the FirebaseRecyclerAdapter.
-
-
Constructor Summary
Constructors Constructor Description FirebaseRecyclerAdapter(FirebaseRecyclerOptions<T> options)Initialize a RecyclerView.Adapter that listens to a Firebase query.
-
Method Summary
Modifier and Type Method Description voidstartListening()Start listening for database changes and populate the adapter. voidstopListening()Stop listening for database changes and clear all items in the adapter. voidonChildChanged(@NonNull() ChangeEventType type, @NonNull() DataSnapshot snapshot, int newIndex, int oldIndex)voidonDataChanged()voidonError(@NonNull() DatabaseError error)ObservableSnapshotArray<T>getSnapshots()Returns the backing ObservableSnapshotArray used to populate this adapter. TgetItem(int position)Gets the item at the specified position from the backing snapshot array. DatabaseReferencegetRef(int position)Returns the reference at the specified position in this list. intgetItemCount()voidupdateOptions(@NonNull() FirebaseRecyclerOptions<T> options)Re-initialize the Adapter with a new set of options. voidonBindViewHolder(@NonNull() VH holder, int position)-
Methods inherited from class androidx.recyclerview.widget.RecyclerView.Adapter
bindViewHolder, createViewHolder, findRelativeAdapterPositionIn, getItemCount, getItemId, getItemViewType, getStateRestorationPolicy, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onCreateViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, setStateRestorationPolicy, unregisterAdapterDataObserver -
Methods inherited from class com.firebase.ui.common.BaseChangeEventListener
onChildChanged, onDataChanged, onError -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
FirebaseRecyclerAdapter
FirebaseRecyclerAdapter(FirebaseRecyclerOptions<T> options)
Initialize a RecyclerView.Adapter that listens to a Firebase query.
-
-
Method Detail
-
startListening
void startListening()
Start listening for database changes and populate the adapter.
-
stopListening
void stopListening()
Stop listening for database changes and clear all items in the adapter.
-
onChildChanged
void onChildChanged(@NonNull() ChangeEventType type, @NonNull() DataSnapshot snapshot, int newIndex, int oldIndex)
-
onDataChanged
void onDataChanged()
-
getSnapshots
@NonNull() ObservableSnapshotArray<T> getSnapshots()
Returns the backing ObservableSnapshotArray used to populate this adapter.
-
getItem
@NonNull() T getItem(int position)
Gets the item at the specified position from the backing snapshot array.
-
getRef
@NonNull() DatabaseReference getRef(int position)
Returns the reference at the specified position in this list.
- Parameters:
position- index of the reference to return
-
getItemCount
int getItemCount()
-
updateOptions
void updateOptions(@NonNull() FirebaseRecyclerOptions<T> options)
Re-initialize the Adapter with a new set of options. Can be used to change the querywithout re-constructing the entire adapter.
-
onBindViewHolder
void onBindViewHolder(@NonNull() VH holder, int position)
-
-
-
-