我无法从基础数据库中获取数据。我在onStart()方法中使用了FirebaseRecyclerAdapter

时间:2018-04-11 18:15:09

标签: java android firebase firebase-realtime-database

 @Override
    protected void onStart() {
        super.onStart();
        FirebaseRecyclerAdapter <ZedMate,ZedmateViewHolder> FBRA = new FirebaseRecyclerAdapter<ZedMate, ZedmateViewHolder>(
                ZedMate.class,
                R.layout.zedmate,
                ZedmateViewHolder.class,
                databaseReference
        ) {
            @Override
            protected void populateViewHolder(ZedmateViewHolder viewHolder, ZedMate model, int position) {
                            viewHolder.setTitle(model.getTitle());
                            viewHolder.setDesc(model.getDesc());
            }
        };
        recyclerView.setAdapter(FBRA);
    }

 public static class ZedmateViewHolder extends RecyclerView.ViewHolder{
    public ZedmateViewHolder(View itemView){
        super(itemView);
        View mView = itemView;
    }
    public void setTitle(String title){
        TextView ptitle = (TextView)itemView.findViewById(R.id.mytitle);
        ptitle.setText(title);
    }
    public void setDesc(String desc){
        TextView pdesc = (TextView)itemView.findViewById(R.id.mydescription);
        pdesc.setText(desc);
    }
}

0 个答案:

没有答案