android - 如何在 firebase Android 中搜索 Child 的值

标签 android firebase firebase-realtime-database

enter image description here

DatabaseReference databaseReference=mDatabase;
        String queryText="Hotel";
        databaseReference.orderByChild("Coupon")
                .startAt(queryText)
                .endAt(queryText+"\uf8ff");

Here I attached the code which I used to get child names of "Coupon" when I entered the "Hotel" query under the Coupon.But I got blank.I supposed to get Hotel1,Hotel2 object.I'm new to firebase.So hope your support .Thanks in advance.

最佳答案

在网络版本中,他们使用称为 ElasticSearch 的东西,您可以尝试在此处阅读更多内容:https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html

但是对于 Android,我认为没有任何功能可以执行这样的搜索。我要做的就是查询所有记录,然后自己过滤它们:

DatabaseReference databaseReference = mDatabase;
mDatabase.addValueEventListener(new ValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    for(DataSnapshot val : dataSnapshot.getChildren()){
        //I am not sure what record are you specifically looking for
        //This is if you are getting the Key which is the record ID for your Coupon Object
        if(val.getKey().contains("Hotel")){
            //Do what you want with the record
        }

        //This is if your are querying for the hotel child
        if(val.child("hotel").getValue(String.class).contains("Hotel")){
            //Do what you want with the record
        }
    }
}
@Override
public void onCancelled(FirebaseError firebaseError) {

}

}

关于android - 如何在 firebase Android 中搜索 Child 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43511467/

相关文章:

java - 用于 SD 卡上图像的 ViewPager 无法正常工作

android - Roboguice 注入(inject)和 Provider 类

android - 编译 'com.firebaseui:firebase-ui:1.0.1' 显示错误

javascript - Firebase Cloud Messaging - 可扩展的应用服务器(同时连接)

swift - 当将值更改为从 firebase 中提取的数据时,变量将恢复为初始值。怎样才能让值(value)留下来?

java - 当标记 android studio 触发时,如何获取我保存在 firebase 中的数据 latlng

javascript - 在 Firebase 中处理用户的在线和离线状态

android - 创建圆形布局的菜单

android - 使用 ActionBar 选项卡在 onCreateView 中获取 Google Map Fragment

javascript - 引用错误,表示变量未定义