1

I want to be able to query the tags from each category eg, Shirts, Pants , etc. In my firebase console i only have Shirts for now.

enter image description here

In my app recouture i have currently 2 users using and a Shirts node. Ideally there would be other categories added to it as well. Eg, Pants, Shoes

enter image description here

I would like for each user to conduct a query on the tags under each category and each would have a similar structure to Shirts.

Hope my question was clear !

calveeen
  • 621
  • 2
  • 10
  • 28
  • you can give path directly to uid after that check here https://stackoverflow.com/questions/32886546/how-to-get-all-child-list-from-firebase-android – Tara Jul 09 '18 at 07:25
  • @Waleed Asim How would you query for the tags, when u call order child by ? Could you explain more? – calveeen Jul 09 '18 at 07:52
  • Can you please add what you have tried already and were you are getting stuck? Also please specify the programming language (kind of annoying when you want to do it in IOS but get a javascript answer) – André Kool Jul 09 '18 at 08:29
  • @Andre Kool after searching through the internet longer what I want is actually a ffirebase query for arrays stored in firebase . I realized that it is not possible and that I need to change the way my data is stored . I don’t have code yet because I didn’t know how to set up the query in the first place. And the language is in java – calveeen Jul 10 '18 at 01:07

1 Answers1

0

Try the following:

FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child(user.getUid()).child("Shirts");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
  @Override
public void onDataChange(DataSnapshot dataSnapshot) {
 for(DataSnapshot ds: dataSnapshot.getChildren()){
      DataSnapshot tags=ds.child("tags");

    for(DataSnapshot datas: tags.getChildren()){
       String tagValues=datas.getValue().toString();
      }

    }
  }
 @Override
public void onCancelled(DatabaseError databaseError) {

   }
});

Here you snapshot is at Shirts then you loop and to be able to access the child tags, then you loop inside the node tags and retrieve the values Style and Tags.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • oh what I want is when the user types Style or Tags in a search bar this particular item will actually appear in the recycler view. So I am wondering how One would order the query by since in on data changed method you wouldn’t be able to have access to the string that the user typed in the search. Thanks for the reply Anw ! – calveeen Jul 09 '18 at 14:42