Reputation: 138969
I have the following Firebase database:
All i want to do, is to display all the lists that belong to a specific user. In this case, i want to display List aaa
and List bbb
that belong to gmail@gmail,com user. With this query:
databaseReference = FirebaseDatabase.getInstance().getReference();
Query query = databaseReference.child("Lists").orderByChild("ListName");
firebaseListAdapter = new FirebaseListAdapter<ListModel>(this, ListModel.class, android.R.layout.simple_list_item_1, query) {
@Override
protected void populateView(View v, ListModel slm, int position) {
((TextView)v.findViewById(android.R.id.text1)).setText(slm.getListName());
}
};
I achieve to display all the lists but i want to display only the lists that belong to a single user and has the value of true
. How can i do that?
Thanks in advance!
Upvotes: 0
Views: 3334
Reputation: 533
There are two ways to achieve this behaviour.
Query query = DatabaseRef.getReference().child("Lists").orderByChild("Users").equals("gmail@gmail,com")
Then add the ChildEventListener to this reference
Lists \gmail@gmail,com \listName aaa \listName bbb
You can get data from this structure from below reference:
Query query = DatabaseRef.getInstance().child("Lists").child("gmail@gmail,com")
Then add ChildEventListener listener with your ref object.
Hope this will work for you..
--- Edited ---- Try using this:
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference ref = firebaseDatabase.getReference().child("Lists").orderByChild("Users").equalTo("gmail@gmail,com");
ref.addChildEventListener(New ChildEventListener......);
Upvotes: 1