Class FirebaseListAdapter<T>

  • Type Parameters:
    T - The class type to use as a model for the data contained in the children of the given Firebase location
    All Implemented Interfaces:
    Adapter, ListAdapter, SpinnerAdapter, androidx.lifecycle.LifecycleObserver, com.firebase.ui.common.BaseChangeEventListener<com.google.firebase.database.DataSnapshot,​com.google.firebase.database.DatabaseError>, ChangeEventListener

    public abstract class FirebaseListAdapter<T>
    extends BaseAdapter
    This class is a generic way of backing an Android ListView with a Firebase location. It handles all of the child events at the given Firebase location. It marshals received data into the given class type.

    See the README for an in-depth tutorial on how to set up the FirebaseListAdapter.

    • Field Detail

      • mLayout

        protected final int mLayout
    • 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<com.google.firebase.database.DataSnapshot,​com.google.firebase.database.DatabaseError>
      • onDataChanged

        public void onDataChanged()
        Specified by:
        onDataChanged in interface com.firebase.ui.common.BaseChangeEventListener<com.google.firebase.database.DataSnapshot,​com.google.firebase.database.DatabaseError>
      • onError

        public void onError​(@NonNull
                            com.google.firebase.database.DatabaseError error)
        Specified by:
        onError in interface com.firebase.ui.common.BaseChangeEventListener<com.google.firebase.database.DataSnapshot,​com.google.firebase.database.DatabaseError>
      • getItem

        @NonNull
        public T getItem​(int position)
        Specified by:
        getItem in interface Adapter
      • getRef

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

        public int getCount()
        Specified by:
        getCount in interface Adapter
      • getItemId

        public long getItemId​(int i)
        Specified by:
        getItemId in interface Adapter
      • getView

        @NonNull
        public View getView​(int position,
                            @Nullable
                            View convertView,
                            @NonNull
                            ViewGroup parent)
        Specified by:
        getView in interface Adapter
      • populateView

        protected abstract void populateView​(@NonNull
                                             View v,
                                             @NonNull
                                             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. The first two arguments correspond to the mLayout and mModelClass given to the constructor of this class. The third argument is the item's position in the list.

        Your implementation should populate the view using the data contained in the model.

        Parameters:
        v - The view to populate
        model - The object containing the data used to populate the view
        position - The position in the list of the view being populated