【发布时间】:2018-11-18 22:51:58
【问题描述】:
我有这个数据结构来创建巴士时刻表并提供时间。我不确定如何获得获得时间的钥匙
"Schedules" : {
"Apu-to-vista" : {
"11:00" : "true",
"12:00" : "true",
"13:00" : "true",
"13:30" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:00" : "true",
"20:30" : "true"
},
"vista-to-apu" : {
"11:35" : "true",
"12:00" : "true",
"13:00" : "true",
"13:15" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:20" : "true",
"20:30" : "true"
}
}
如果我这样做,我想得到钥匙mDatabase.getReference("Schedules").child("Apu-to-vista")
这是我迄今为止尝试过的
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.vista, container, false);
mDatabase = FirebaseDatabase.getInstance();
fromAPU = mDatabase.getReference("Schedules").child("Apu-to-vista");
toAPU = mDatabase.getReference("Schedules").child("Vista-to-apu");
recyclerView = (RecyclerView) view.findViewById(R.id.fromAPURecycler);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
adapter = new FirebaseRecyclerAdapter<Schedule, ViewHolder>(
Schedule.class, R.layout.card_view, ViewHolder.class, toAPU.orderByKey()
){
@Override
protected void populateViewHolder(ViewHolder viewHolder, Schedule model, int position) {
viewHolder.mTime.setText(getRef(position).getKey());
}
};
recyclerView.setAdapter(adapter);
return view;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public final TextView mTime;
public ViewHolder(View itemView) {
super(itemView);
mTime = (TextView) itemView.findViewById(R.id.text_holder);
}
}
我尝试使用 firebase 回收器适配器创建仅包含 String timeText 的类,并将其放入 recyclerview。但是有一个错误 错误说没有附加适配器:跳过布局
我只是 android 的初学者,有人可以帮助我。谢谢
【问题讨论】:
-
getRef(position).getKey()返回什么? -
我试图记录它,但它没有给我任何东西,因为错误发现没有连接适配器
-
This 是一种推荐的方式,您可以通过这种方式从 Firebase 实时数据库中检索数据并使用
FirebaseRecyclerAdapter将其显示在RecyclerView中。
标签: java android firebase firebase-realtime-database android-recyclerview