【问题标题】:Firebase Recycler Adapter Querying databaseFirebase Recycler Adapter 查询数据库
【发布时间】:2020-10-16 16:34:49
【问题描述】:

我正在尝试从 firebase 实时数据库中检索特定数据。我知道对 firebase 数据库进行复杂查询是不可能的。

这是我的数据库快照,我要做的是首先使用 count 对我的数据库进行排序,因此我使用了 query .orderByChild("count") 并将其传递给 Recycler 选项。好没问题。但现在我还想要的是,如果仅当推荐 = 推荐时,应该显示数据。即双重查询。

我认为我们不能在实时数据库中使用双重查询,所以我所做的是......

/*
condition =
  recyclerView = Linearlayout manager
  setQuery = orderbychild count
*/

  //actual logic for hiding non required data

        if (model.getRecommendation().equals("recommended")) {

            holder.recommendationLayout.setVisibility(View.VISIBLE);

        }
        else {

            holder.hideView.setVisibility(View.GONE);
            holder.hideView.getLayoutParams().height = 0;
            holder.hideView.getLayoutParams().width = 0;

            ViewGroup.MarginLayoutParams layoutParams =
            (ViewGroup.MarginLayoutParams) holder.hideView.getLayoutParams();
            layoutParams.setMargins(0, 0, 0, 0);

            holder.hideView.requestLayout();
       }

但是当我将布局管理器更改为 GridLayoutManager

遗憾的是,它在不推荐产品标签的地方保留空白

所以我的问题是我们怎样才能避免这个空白,或者有什么方法可以对我的数据库进行排序并传递双重查询或其他什么?

【问题讨论】:

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


    【解决方案1】:
    1. 更改列表项的根布局的 layout_width = wrap_content..
    2. 传递您的数组列表

    Collections.sort(itemsLists);

    然后在您的模型类上添加一个 compareTo 方法... 参考这里:-https://howtodoinjava.com/sort/collections-sort/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多