-1

How I can get text data based on Firebase database structure like in the picture?

I already create some function to get a text data with "fromID" as a parameter. Now, how I can get the text data based on "fromID" and "toID" as a parameter? Thank you.

Overview of Firebase Database Structure This is my code

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Please show what Android code you've written thus far. For example, we're don't know what your chat activity even looks like. See about having a [mcve] – OneCricketeer Jul 11 '18 at 04:42
  • @AlexMamo I was wondering why you chose that duplicate instead of the one I proposed? – André Kool Jul 11 '18 at 09:11
  • @AndréKool Because that duplicate is in Javascript and the OP is asking for a solution in Android. As you can see the tag and the code from it's picture. – Alex Mamo Jul 11 '18 at 09:15
  • @AlexMamo Actually the question I proposed doesn't have a language tag, it only uses javascript in the answers. It also has more (extencive) answers and it's being used as the go-to dupe target for these kind of questions. Is it maybe a good idea to add it to the duplicate list on this question? – André Kool Jul 11 '18 at 09:19
  • @AndréKool That's a good idea, just added it. – Alex Mamo Jul 11 '18 at 09:28
  • OMG the abuse of power – Peter Haddad Jul 11 '18 at 10:00

2 Answers2

0

you can use the sample below. first, make a model and set the data using an adapter.

 mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(from_user);
     String text= dataSnapshot.child("name").getValue().toString();
sudesh regmi
  • 536
  • 4
  • 12
0

You can't do this with Firebase Realtime database without some significant changes in your database structure. Realtime Database doesn't have the capability to perform filtering on multiple conditions (in SQL terms, "multiple where clauses"). If you want to check for matches on multiple properties like fromID1 and toID, you'll have to create a composite field that contains a combination of those two properties. For instance, you'll need a String value that has fromID1 and toID concatenated together like this:

fromID1_toID

You can also take a look at my answer from this post.

Note, if you'll later decide to to change your database to Firestore, please note that this feature is available, you can filter on multiple conditions.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193