Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] Problem retrieving data from firebase database path problem – Android

Posted on November 11, 2022 By

Solution 1 :

Change this:

    Query firebaseSearchQuery = searchforData.orderByChild(keyNameOfFarmacy).orderByChild("others").orderByChild("Nome").startAt(searchText).endAt(searchText + "uf8ff");

into this:

    Query firebaseSearchQuery = searchforData.child(keyNameOfFarmacy).child("others").orderByChild("Nome").startAt(searchText).endAt(searchText + "uf8ff");

You already have access to others and to the key so just use child for that and orderByChild for Nome.

Problem :

I want to retrieve data from the database and insert it into a recycleview.
The problem is that I don’t know who I can get to the data inside the dataset.

First, take a look at my dataset structure: Json added below:

"Places" : {
"-M11-OIIHbKTVqCJ-Swv" : {
  "name" : "Farmacia Pagani Dr. Roberto",
  "others" : {
    "01" : {
      "Nome" : "Ambilify",
      "Price" : 100
    },
    "02" : {
      "Nome" : "Acetaminophoen",
      "Price" : 120
    }
  }
},
"-M11-OJJCGAPdJUknLXX" : {
  "name" : "FARMACIA DR. TUMIATTI MARIANO",
  "others" : {
    "01" : {
      "Nome" : "Ambilify",
      "Price" : 100
    },
    "02" : {
      "Nome" : "Acetaminophen",
      "Price" : 120
    }
  }
}
},

So what I want is: since I have the key “-M11-OIIHbKTVqCJ-Swv” I want to perform a search inside the object with this key. To do so I need to access Places/key object(-M11-OIIHbKTVqCJ-Swv)/others and then to perform a search based on Nome(means name in Italian). I want to return Nome: Ambilify Price : 100

This is what I did :

 private void firebaseUserSearch(String searchText) {
    DatabaseReference  searchforData = FirebaseDatabase.getInstance().getReference("Places");

    Toast.makeText(FirebaseSearch.this, "Started Search", Toast.LENGTH_LONG).show();
    System.out.println("keyNameOfFarmacy"+keyNameOfFarmacy);
    Query firebaseSearchQuery = searchforData.orderByChild(keyNameOfFarmacy).orderByChild("others").orderByChild("Nome").startAt(searchText).endAt(searchText + "uf8ff");
    FirebaseRecyclerAdapter<DataDetails, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<DataDetails, UsersViewHolder>(
            DataDetails.class,
            R.layout.list_layout,
            UsersViewHolder.class,
            firebaseSearchQuery
    ) {
        @Override
        protected void populateViewHolder(UsersViewHolder viewHolder, DataDetails model, int i) {
            viewHolder.getDetails(model.getNome(), model.getPrice());
            viewHolder.setDetails(model.getNome(), model.getPrice());
        }

    };
    mResultList.setAdapter(firebaseRecyclerAdapter);
}

I have a problem with this part of the code because: orderByChild can be used just once.

Can anyone tell me how can I get the data please, I lost the last 2 3 h searching how to do it and I didn’t find anything. Thank you in advance.

READ  [FIXED] vue.js - How to handle incoming share content in capacitor on Android
Powered by Inline Related Posts
Android Tags:android, firebase, firebase-realtime-database

Post navigation

Previous Post: [FIXED] java – MVVM with Room and LiveData – How to get List from LiveData
Next Post: [FIXED] android – Xamarin.Forms.Droid Resource, Ambiguous Terms/ Build Action’s Randomly Changing Missing Resources

Related Posts

[FIXED] java – This is related to firestore read request. Firestore implemented in android application Android
[FIXED] java – Circle stretched when rendered in OpenGL ES 2 Android
[FIXED] Video Compression library in Java android? Android
[FIXED] android – Converting SimpleCursorAdapter code from Java to Kotlin Android
[FIXED] Android Jetpack Navigation component Condtional navigation issue Android
[FIXED] java – I’m trying to use EditText from Material Design – and I’m getting runtime exception Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • How do you stop a number from calling you permanently?
  • What are the main features of Islamic education?
  • Is the Jeep 4xe worth it?
  • How does the ringer work on cast iron?
  • What is the biggest size interior door?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme