如何访问firebase实时数据库的子项

时间:2018-03-18 03:20:01

标签: android firebase firebase-realtime-database

我使用过FirbaseRecyclerAdapter但是我很难找到跟随孩子的价值是我用过的代码

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        Toast.makeText(this, "Created", Toast.LENGTH_SHORT).show();
        listitems = new ArrayList<>();
        databaseReference =  FirebaseDatabase.getInstance().getReference().child("content");
    }


    @Override
    protected void onStart() {
        super.onStart();

        FirebaseRecyclerAdapter<Listitem ,BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Listitem, BlogViewHolder>(
                Listitem.class,R.layout.list_item,BlogViewHolder.class,databaseReference
        ) {
            @Override
            protected void populateViewHolder(BlogViewHolder viewHolder, Listitem model, int position) {
                viewHolder.sethead(model.getHead());
                viewHolder.setdesc(model.getDesc());



            }

        };
        recyclerView.setAdapter(firebaseRecyclerAdapter);
    }

enter image description here

1 个答案:

答案 0 :(得分:0)

-L7n...Udk3D下有一个额外的duck密钥,这很可能是因为Listitem模型类无法查找head和{ {1}}属性。要修复它,请删除额外的description密钥。