我有一个嵌套的回收站视图设置(包含水平回收站视图的垂直回收站视图),其中几乎所有的东西都可以正常工作,除了为了水平回收站而必须清空填充有数据的数组的那一部分视图。让我们从垂直回收器视图适配器的代码开始,该适配器从Firestore填充阵列,并在底部解释发生了什么:
public void onBindViewHolder(@NonNull final MealPlanDetailsAdapter.MealPlanDetailsViewHolder mpDetailsViewHolder, final int position) {
// Set full address
String fullAddress = mealplanDetailsArrayList.get(position).getAddressLine() + ", " + mealplanDetailsArrayList.get(position).getCity() + ", " +mealplanDetailsArrayList.get(position).getPostalCode();
mpDetailsViewHolder.tvAddress.setText(fullAddress);
// Set restaurant name
mpDetailsViewHolder.tvRestaurant.setText(mealplanDetailsArrayList.get(position).getRestaurantName());
// Menu items
mpDetailsViewHolder.mealplanMenuRecycler.setHasFixedSize(true);
mpDetailsViewHolder.mealplanMenuRecycler.setLayoutManager(new LinearLayoutManager(adapterContext, LinearLayoutManager.HORIZONTAL, false));
String orderId = mealplanDetailsArrayList.get(position).getOrderDetails();
final FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser != null) {
for (UserInfo profile : firebaseUser.getProviderData()) {
userId = profile.getUid();
}
}
// Get menu items
CollectionReference orderReference = firebaseFirestore.collection("Customer_Data").document(userId).collection("Meal_Plans").document(orderId).collection("Placed_Order");
orderReference.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (final QueryDocumentSnapshot orderDocument : queryDocumentSnapshots) {
mealplanMenuArrayList = new ArrayList<>();
// Get image
String restaurantId = mealplanDetailsArrayList.get(position).getRestaurantId();
CollectionReference restaurantQuery = firebaseFirestore.collection("Restaurant_Data").document(restaurantId).collection("Menu_Card");
restaurantQuery.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (QueryDocumentSnapshot menuDocument : queryDocumentSnapshots){
menuItemName = menuDocument.getString("menuItemName");
menuItemImage = menuDocument.getString("menuItemImage");
if (orderDocument.getString("menuItemName").equals(menuItemName)) {
MealplanMenu mealplanMenu = new MealplanMenu(menuItemName, orderDocument.getString("menuItemQuantity"),menuItemImage);
mealplanMenuArrayList.add(mealplanMenu);
}
}
mealplanMenuAdapter = new MealplanMenuAdapter(adapterContext, mealplanMenuArrayList);
mpDetailsViewHolder.mealplanMenuRecycler.setAdapter(mealplanMenuAdapter);
}
});
}
}
});
}
我正在查询上面的2个不同的集合。我需要查询2个不同的集合。如果两个集合中的两个特定值匹配,一个为我提供了我需要的大多数数据,另一个为我提供了图像网址。如您在上面看到的,我正在更新数组:餐计划菜单数组列表=新的数组列表<>();
但是,我要么得到了每个垂直支架的所有水平值,要么只得到了第一个。在哪里可以刷新阵列,以便仅能获得所需的确切信息?