How to implement Firebase Recycler Adapter in newer version of Android 3.1 and higher?

前端 未结 2 1471
旧巷少年郎
旧巷少年郎 2020-12-18 09:05

Basically, what I am trying to do is use a FirebaseRecyclerAdapter and populate the RecyclerView with my custom designed CardView. The

相关标签:
2条回答
  • 2020-12-18 09:23

    In order to be able to display data from the Firebase realtime database you need to start listening for changes and for that you should add the following line of code in the onStart() method:

    @Override
    protected void onStart() {
        super.onStart();
        FBRA.startListening();
    }
    

    To stop listening foir changes you need add the following line of code in the onStop() method like this:

    @Override
    protected void onStop() {
        super.onStop();
        if(FBRA != null) {
            FBRA.stopListening();
        }
    }
    

    Please see my answer from this post where I have explained why you should remove the listener.

    P.S. Please also don't forget to make the FBRA a global variable and remove FirebaseRecyclerAdapter<ServiceClass, ServiceViewHolder> from the declaration of the object.

    0 讨论(0)
  • 2020-12-18 09:38

    This is more of an advice. If you want to continue using the old method to populate your recyclerview ie The "populateViewHolder" method instead of the new "onBindViewHolder" method just use this;

    implementation 'com.firebaseui:firebase-ui:1.0.1'
    

    instead of upgraded firebase-ui versions

    0 讨论(0)
提交回复
热议问题