其中,在用户ID子项下,我通过系统日期创建了一个子项。日期子项将从系统日期创建并且将多于一个。假设我有系统日期子项列表我将从我的firebase数据库中获取并在Recyclerview中显示?我如何实现这一目标?数据模型类是什么?
答案 0 :(得分:0)
您需要创建自己的适配器:
我能想到的最低限度是:
public static class MenuHomeAdapter extends RecyclerView.Adapter<MenuViewHolder> {
ArrayList<Menu> items = new ArrayList<>();
public MenuHomeAdapter(Firebase ref) {
ref.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot snapshot) {
items.clear();
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Menu menu = postSnapshot.getValue(Menu.class);
items.add(menu);
}
notifyDataSetChanged();
}
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
public MenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
return new MenuViewHolder(view);
}
public void onBindViewHolder(MenuViewHolder holder, int position) {
Menu item = items.get(position);
holder.getTitleView().setText(item.getTitle());
}
public int getItemCount() {
return items.size();
}
};