简体   繁体   中英

Fetching specific data from firebase in android studio

Trying to fetch related data from firebase

I am new in Android and I am stuck here, want to retrieve data from Firebase where "del_id = 1" and "date = 2019-3-18" but I don't know how to write as Firebase way to retrieve what I want, Image above will further demonstrate what I have tried and what I want.

Your answer will be highly valuable for me.

The following line of code:

invSnapsjot.getValue(Invoice.class)

Returns an object of type Invoice and not a DataSnapshot object so you can call .child() method on it.

If you want to get a specific element (del_id = 1) , you should simply use a query that looks like this:

myDatabase.orderByChild("del_id").equalTo("1").addValueEventListener(/* ... */);

Unfortunately, Firebase realtime database does not support queries on multiple properties but there is still a workaround for that, so please see my answer from the following post:

If you want to write or update value at that time you need to take .addValueEventListener

If you want to only set your value in firebase you directly set value without using .addValueEventListener

More details refer this link https://firebase.google.com/docs/database/android/read-and-write

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM