gpt4 book ai didi

java - 如何同时更新和删除数据 Realtime Firebase

转载 作者:行者123 更新时间:2023-12-01 21:19:59 25 4
gpt4 key购买 nike

我想同时更新状态并删除打开的状态。 This is my database

 private void loadOrders() {
FirebaseRecyclerOptions<Orders> options = new FirebaseRecyclerOptions.Builder<Orders>()
.setQuery(requests,Orders.class)
.build();
adapter = new FirebaseRecyclerAdapter<Orders, AdminOrderViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull AdminOrderViewHolder viewHolder, final int position, final Orders model) {
viewHolder.txtTableNo.setText("Table No:" + model.getTableNo());
viewHolder.txtOrderId.setText(adapter.getRef(position).getKey());
viewHolder.txtOrderStatus.setText(Common.convertCodeToStatus(model.getStatus()));

//New event button
viewHolder.btnEdit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
showUpdateDialog(adapter.getRef(position).getKey(),adapter.getItem(position));
}
});

viewHolder.btnRemove.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
deleteOrder(adapter.getRef(position).getKey());
}
});

viewHolder.btnDetail.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Intent orderDetail = new Intent(RestaurantViewCompleteOrder.this,OrderDetail.class);
Common.currentRequest = model;
orderDetail.putExtra("OrderId", adapter.getRef(position).getKey());
startActivity(orderDetail);
}
});

viewHolder.btnBill.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
showUpdatePayment(adapter.getRef(position).getKey(),status,open);
}
});

我想在这里更新和删除

 private void showUpdatePayment(final String key,String status,String open) {
Query mUpdate =requests.child(key).child("status").child("open");

adapter.notifyDataSetChanged();
}

最佳答案

HashMap<String, Object> dataMap = new HashMap<>();
dataMap.put("status", 1);
dataMap.put("open",FieldValue.delete());

更新dataMap将更新状态并删除打开

希望这会有所帮助

关于java - 如何同时更新和删除数据 Realtime Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58855306/

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