[英]Fetching specific data from firebase in android studio
Trying to fetch related data from firebase 试图从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. 我是Android的新手,我被困在这里,想要从Firebase中检索“del_id = 1”和“date = 2019-3-18”的数据,但我不知道怎么写Firebase的方式来检索我想要的东西,上面的图片将进一步展示我尝试过的和我想要的东西。
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. 返回
Invoice
类型的对象而不是 DataSnapshot对象,因此您可以在其上调用.child()
方法。
If you want to get a specific element (del_id = 1)
, you should simply use a query that looks like this: 如果要获取特定元素
(del_id = 1)
,您应该只使用如下所示的查询:
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: 不幸的是,Firebase实时数据库不支持多个属性的查询,但仍然有一个解决方法,所以请从以下帖子看到我的答案:
If you want to write or update value at that time you need to take .addValueEventListener 如果要在此时写入或更新值,则需要使用.addValueEventListener
If you want to only set your value in firebase you directly set value without using .addValueEventListener 如果你想只设置在火力你的价值 ,你直接设置值,而无需使用.addValueEventListener
More details refer this link https://firebase.google.com/docs/database/android/read-and-write 更多详细信息,请参阅此链接https://firebase.google.com/docs/database/android/read-and-write
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.