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

时间:2019-11-14 11:04:28

标签: java android firebase-realtime-database firebaseui

我想更新状态并同时删除打开的文件。 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();
    }

1 个答案:

答案 0 :(得分:0)

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

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

希望这会有所帮助