use of com.example.app_restaurante.Adapter.AdapterFood in project MDA_APP_RESTAURANTE by karlaogh99.
the class FoodListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_list);
FirebaseFirestore db = FirebaseFirestore.getInstance();
// Read from the database
listFood = new ArrayList<>();
recycler_menu = (RecyclerView) findViewById(R.id.recycler_food);
recycler_menu.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);
db.collection("Food").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful() && getIntent() != null) {
Category catId = (Category) getIntent().getSerializableExtra("Categoria");
for (QueryDocumentSnapshot document : task.getResult()) {
if (catId.getName().equals((String) document.get("IdCategoria"))) {
Food food = new Food("", "", "", "", "");
food.setName((String) document.get("Nombre"));
food.setDescripcion((String) document.get("Descripcion"));
food.setId((String) document.get("IdCategoria"));
food.setPrice((String) document.get("Precio"));
food.setImage((String) document.get("Image"));
listFood.add(food);
}
}
AdapterFood adapter = new AdapterFood(listFood);
recycler_menu.setAdapter(adapter);
}
}
});
}
Aggregations