gpt4 book ai didi

java - 添加从我的 RecycleView 中选择的项目

转载 作者:搜寻专家 更新时间:2023-11-01 09:26:07 25 4
gpt4 key购买 nike

我只想将从我的 RecycleView 中选择的项目添加到 Firebase,但它会将 RecycleView 中的所有项目添加到 Firebase。

    @Override
public void onAddClick(int position) {
FoodInfo selectedItem = mfoodinfo.get(position);
final String selectedKey = selectedItem.getFoodname();

StorageReference imageRef = firebaseStorage.getReferenceFromUrl(selectedItem.getImageUrl());
imageRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {

final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Order");
databaseReference.child(selectedKey).setValue(mfoodinfo);
Toast.makeText(Menu.this, "Order Successful!!", Toast.LENGTH_SHORT).show();
}
});

}

有人帮我解决吗?

最佳答案

试试这个代码:(将“mfoodinfo”替换为“selectedItem”)

    @Override
public void onAddClick(int position) {
final FoodInfo selectedItem = mfoodinfo.get(position);
final String selectedKey = selectedItem.getFoodname();

StorageReference imageRef = firebaseStorage.getReferenceFromUrl(selectedItem.getImageUrl());
imageRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {

final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Order");
databaseReference.child(selectedKey).setValue(selectedItem);
Toast.makeText(Menu.this, "Order Successful!!", Toast.LENGTH_SHORT).show();
}
});

}

关于java - 添加从我的 RecycleView 中选择的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50549545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com