Single list with data from sub (nested) - node Firebase

时间:2018-02-03 11:04:23

标签: android firebase firebase-realtime-database

Is it possible to create a list with FirebaseRecyclerAdapter or other, with all name of all month? The problem is that name are in a sub-node as image.

enter image description here

I try with this code, but I get an empty list. If you can do this, how can I do?

mAdapter2 = new FirebaseRecyclerAdapter<DailyItem, TestHolder>(DailyItem.class, R.layout.test_layout_item, TestHolder.class, mDatabase.child("Year").child("2018")) {
    @Override
    protected void populateViewHolder(final TestHolder viewHolder, final DailyItem model, final int position) {
        final DatabaseReference postRef = getRef(position);
        final String postKey = postRef.getKey();
        viewHolder.bindToPost(model);
    }
};
mRecycler2.setAdapter(mAdapter2);

I looked at other questions but I did not find a similar situation. Thank you

1 个答案:

答案 0 :(得分:0)

FirebaseRecyclerAdapter(以及FirebaseUI中的其他适配器)显示位置或查询的直接子节点。虽然它们可以为每个子节点显示较低级别的属性,但它们不支持将嵌套子节点显示为顶级列表项。

一般情况下,我建议您在数据库中对JSON进行建模,以反映您在屏幕上显示的内容。因此,如果要在屏幕上显示月份列表,请考虑在数据库中存储列表月份。

此列表可以替换当前嵌套的树。但它也可能是额外的数据。在NoSQL数据库中复制数据非常常见。有关此主题的更多信息,建议您阅读NoSQL data modeling