0

Now that FirebaseRecyclerAdapter allows us to override methods, do we have any method that could be overridden to check if there is a child present under Database Reference node? If there is no child we should be able to update UI accordingly.

Until now, there was no way we could it, unless we attach an EventListener separately to the Ref node and check if DataSnapshot has any child, which is just overhead, redundant task I thought.

Any help is very much appreciated. Thank you!

Nishanth Sreedhara
  • 1,266
  • 1
  • 19
  • 34
  • 1
    There has been an `onDataChanged` method for some time now for this purpose: https://stackoverflow.com/questions/40201574/how-to-dismiss-a-progress-bar-even-if-there-is-no-view-to-populate-in-the-fireba/40204298#40204298 – Frank van Puffelen Jan 27 '18 at 18:53

1 Answers1

1

If I understand your question you have a node ref in firebase that lists items and you want to check if the children of these items exist.

If this is your case then follow this:

lets say your data structure looks like that:

    AnyNode
    | 
    item1
    |------name="some name"

     -----description="some description"

    item2
     |------name="some name"

     -------description="some description"

If you now pass DataReference as (AnyNode) to firebase recycler adapter then this means that you want to list (item1) then (item2) ..... I assume you know how to do that.

Now your problem must be to know if (name) or (description) exist.

So you check that in OnBindViewHolder of your adapter like that:

     //in OnBindViewHolder

      if(model.getName() ==null){
       //name doesn't exist

       }else{
        //name exist
        } 


        if(model.getDescription() ==null){
       //description doesn't exist

       }else{
        //description exist
        }

(model) is the name of your POJO class.

Hope it helps.

Hasan Bou Taam
  • 4,017
  • 2
  • 12
  • 22
  • Thank you for taking time to answer! My question was, if both item1 and item2 were not there, i should be able to show some message or progressBar. And it should be done without adding extra eventListener to that AnyNode. – Nishanth Sreedhara Jan 28 '18 at 03:53