【问题标题】:How to show items on RecyclerView Android based on the values of a child如何根据孩子的值在 RecyclerView Android 上显示项目
【发布时间】:2019-05-14 17:43:07
【问题描述】:

我需要根据孩子的值检索 Firebase 实时数据库中的一些数据。

例如,这里我只需要显示accepted==true 所在的孩子(通知)。

我在RecyclerView 上传递我的值并带有引用,而不创建列表。

【问题讨论】:

    标签: java android firebase firebase-realtime-database android-recyclerview


    【解决方案1】:

    要获取所有通知“WHERE”accepted 属性包含true 的值,您需要使用查询。在代码中,如下所示:

    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    DatabaseReference notificationsRef = rootRef.child("Notifications");
    Query query = notificationsRef.orderByChild("accepted").equalTo(true);
    query.addListenerForSingleValueEvent(/* ... */);
    

    【讨论】:

      【解决方案2】:

      你试过了吗?

      https://firebase.google.com/docs/database/android/lists-of-data#filtering_data

      你可以使用equalTo()方法来过滤数据。

      【讨论】:

      • 我试过 .child("Notifications").orderBy("accepted").equalTo(true)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2018-09-01
      相关资源
      最近更新 更多