4

FireBase Database image

I want to search a condition if user says MSCS,then Search should check -> condition that MSCS is equal to 1 then get all the data like SJSU(University Name) and CA (City Name) in my Android Application show as a Listview/Fragmentview.

I tried How to search for a value in firebase Android but I'm unable to figure it out.

Community
  • 1
  • 1
user2536273
  • 69
  • 2
  • 6

2 Answers2

3

Sounds that you are looking for something like the following.

mDatabase.orderByChild("MSCS").equalTo(1).addListenerForSingleValueEvent(
    new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //data will be available on dataSnapshot.getValue();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.w(TAG, "getUser:onCancelled", databaseError.toException());
        }
});

Let me know if this works for you :)

adolfosrs
  • 9,286
  • 5
  • 39
  • 67
  • Actually I'm planning a search where user select MSCS..and university name has to shown in the Listview . I'm bit confused with onDataChange method how it can be useful – user2536273 Jun 20 '16 at 19:51
  • @user2536273 what do you mean user select the MSCS? you can search for whatever MSCS you want by using `equalTo(MSCSValue)`. `onDataChange` is a callback that will be called with a snapshot of the data at this location. It will also be called each time that data changes. – adolfosrs Jun 20 '16 at 23:56
  • http://stackoverflow.com/questions/43733318/how-to-search-and-fetch-perticuler-data-from-firebase-database – Aditya Vyas-Lakhan May 02 '17 at 08:26
3

Firebase equalTo(String value) method only returns value if it matches exactly. It is not like SQL LIKE query