Recyklerview z Firebase tylko jedno dziecko
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();
}
};
CB20 138 Najmi