beastlyCoder
beastlyCoder

Reputation: 2401

Searching for EditText value from Firebase

I previously posted a question about how to search for an edittext's value in firebase and realized how I had my database set up was wrong. Now I have my data formatted like this:

{
  "Aaron A" : {
    "allDj" : {
      "-Le5EpHND7KF--XOT7Lc" : "hahahaha",
      "-Le5EsTfNaQ9h3BVeZRw" : "hahahaha",
      "-Le5Fgurpir7bIN3agRb" : "yousucks",
      "-Le5IsCThArSKGRTPnN5" : "ffffggg"
    }
  },
  "allDeeJays" : {
    "-Le5FguoZsnT2lejgAkZ" : "yousucks",
    "-Le5IsCPK69NTbgbgUUo" : "ffffggg",
    "-Le5J5CmPkddSaK_MgpG" : "ahhhaahhaahha"
  }
}

I want to be able to search through "allDeeJays", here is what I have so far:

query = mProfileDatabase.orderByChild("allDeeJays")
                      .startAt(t.getText().toString()).endAt(t.getText().toString() + "\uf8ff");

I can't wrap my head around why this doesn't work, any help plus an explination would be greatly appreciated.

EDIT

After replacing what I had with:

        query = mProfileDatabase.child("allDeeJays")
                .orderByValue()
                .startAt(t.getText().toString()).endAt(t.getText().toString() + "\uf8ff");

I'm getting a new error, logcat does not specify what line it is on:

 com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.android.heydj.DjProfile

Upvotes: 0

Views: 438

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599621

The allDeeJays node in your JSON doesn't have a string value, so your conditions (like .startAt(t.getText().toString())) won't return anything.

You're probably looking for:

query = mProfileDatabase.child("allDeeJays")
                  .orderByValue()
                  .startAt(t.getText().toString()).endAt(t.getText().toString() + "\uf8ff");

Upvotes: 1

Related Questions