Class FirebaseRecyclerAdapter<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>

  • Type Parameters:
    T - The Java class that maps to the type of objects stored in the Firebase location.
    VH - The RecyclerView.ViewHolder class that contains the Views in the layout that is shown for each object.
    All Implemented Interfaces:
    androidx.lifecycle.LifecycleObserver, com.firebase.ui.common.BaseChangeEventListener<com.google.firebase.database.DataSnapshot,​com.google.firebase.database.DatabaseError>, ChangeEventListener

    public abstract class FirebaseRecyclerAdapter<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
    extends androidx.recyclerview.widget.RecyclerView.Adapter<VH>
    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 README for an in-depth tutorial on how to set up the FirebaseRecyclerAdapter.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class androidx.recyclerview.widget.RecyclerView.Adapter

        androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T getItem​(int position)  
      int getItemCount()  
      com.google.firebase.database.DatabaseReference getRef​(int position)  
      ObservableSnapshotArray<T> getSnapshots()  
      void onBindViewHolder​(VH holder, int position)  
      protected abstract void onBindViewHolder​(VH holder, int position, T model)  
      void onChildChanged​(com.firebase.ui.common.ChangeEventType type, com.google.firebase.database.DataSnapshot snapshot, int newIndex, int oldIndex)  
      void onDataChanged()  
      void onError​(com.google.firebase.database.DatabaseError error)  
      void startListening()  
      void stopListening()  
      void updateOptions​(FirebaseRecyclerOptions<T> options)
      Re-initialize the Adapter with a new set of options.
      • Methods inherited from class androidx.recyclerview.widget.RecyclerView.Adapter

        bindViewHolder, createViewHolder, findRelativeAdapterPositionIn, getItemId, getItemViewType, getStateRestorationPolicy, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onCreateViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, setStateRestorationPolicy, unregisterAdapterDataObserver
    • Constructor Detail

    • Method Detail

      • startListening

        public void startListening()
      • stopListening

        public void stopListening()
      • onChildChanged

        public void onChildChanged​(@NonNull
                                   com.firebase.ui.common.ChangeEventType type,
                                   @NonNull
                                   com.google.firebase.database.DataSnapshot snapshot,
                                   int newIndex,
                                   int oldIndex)
        Specified by:
        onChildChanged in interface com.firebase.ui.common.BaseChangeEventListener<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • onDataChanged

        public void onDataChanged()
        Specified by:
        onDataChanged in interface com.firebase.ui.common.BaseChangeEventListener<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • onError

        public void onError​(@NonNull
                            com.google.firebase.database.DatabaseError error)
        Specified by:
        onError in interface com.firebase.ui.common.BaseChangeEventListener<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • getItem

        @NonNull
        public T getItem​(int position)
      • getRef

        @NonNull
        public com.google.firebase.database.DatabaseReference getRef​(int position)
      • getItemCount

        public int getItemCount()
        Specified by:
        getItemCount in class androidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • updateOptions

        public void updateOptions​(@NonNull
                                  FirebaseRecyclerOptions<T> options)
        Re-initialize the Adapter with a new set of options. Can be used to change the query without re-constructing the entire adapter.
      • onBindViewHolder

        public void onBindViewHolder​(@NonNull
                                     VH holder,
                                     int position)
        Specified by:
        onBindViewHolder in class androidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • onBindViewHolder

        protected abstract void onBindViewHolder​(@NonNull
                                                 VH holder,
                                                 int position,
                                                 @NonNull
                                                 T model)
        Parameters:
        model - the model object containing the data that should be used to populate the view.
        See Also:
        onBindViewHolder(RecyclerView.ViewHolder, int)