2

This is the structure of my database. This is the structure of my database.

Restaurant Adapter

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference().child("Restaurant");
DatabaseReference infoRef = rootRef.child("Info");
DatabaseReference categoryRef = rootRef.child("Category");

    FirebaseRecyclerOptions <RestaurantDetails> options = new FirebaseRecyclerOptions.Builder<RestaurantDetails>()
                                                      .setIndexedQuery(infoRef, categoryRef, RestaurantDetails.class)
                                                      .build();

    adapter = new RestaurantAdapter(options);
    recyclerView.setAdapter(adapter);

I am using this format from this link on the structured data. When I did a quick test, the page shows empty. Also, I like to ask if I want to join another table called "Location" as can see from image. Would like to know how cause I believe I only can join 2?

https://firebase.google.com/docs/database/admin/structure-data

UPDATED Am I on the right track? It didn't work and I got another new error which is this:

com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Boolean to type com.isaac.foodie.RestaurantDetails

AND THIS

2020-04-05 21:19:59.149 3490-3490/com.isaac.foodie E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:6594)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
I.Z.
  • 23
  • 8
  • Have you tried to do something like this `rootRef.child("Category").child("Restaurant");` – Ticherhaz FreePalestine Apr 05 '20 at 12:50
  • I have tried but I put it another way which is Restaurant then Category. May I know why Category and then Restaurant? – I.Z. Apr 05 '20 at 13:05
  • First parameter is keyQuery - the Firebase location containing the list of keys to be found in dataRef 2nd parameter is dataRef - the Firebase location to watch for data changes. Each key found at keyRef's location represents a list item. You can refer to this link https://github.com/firebase/FirebaseUI-Android/tree/master/database – Ticherhaz FreePalestine Apr 05 '20 at 13:10
  • I have tried your method and it did not work or maybe I have done something wrong. Please look at the post. I have updated it – I.Z. Apr 05 '20 at 13:25
  • can you check where is the code line for that error – Ticherhaz FreePalestine Apr 05 '20 at 13:57
  • It didn't show which line for the error. Also, would like to clarify, if I want to continue with this format. Will I be getting the result of the name or the boolean, "True"? Because I want to retrieve the name not the boolean – I.Z. Apr 05 '20 at 14:02
  • btw if you want to display all the children from the root `Info` , you can use the simple one – Ticherhaz FreePalestine Apr 05 '20 at 14:56
  • I have done that earlier from the very start before I make this new changes. Because I want to filter by tag, I have to use one of this format. This is where I'm stuck in. Again, to clarify before I continue this, will I get the result true or the category name? I am a newbie to programming so I am learning as I go – I.Z. Apr 05 '20 at 15:02
  • I would suggest you can add a property called `category`. so can query by it – Ticherhaz FreePalestine Apr 05 '20 at 15:05
  • Maybe you misunderstood my previous comment, before I made changes to the DB structure. It was all in one flat tree which was in everything including category and location. When I do the query, it repeated the value of category like cafe, cafe. I want to do it SELECT DISTINCT but Firebase does not play that way. – I.Z. Apr 05 '20 at 15:13
  • I want to retrieve the data something like this but I use this format. Should I change to the one like in the link below? https://stackoverflow.com/questions/35170616/firebase-and-select-distinct – I.Z. Apr 05 '20 at 15:52

0 Answers0