0

I want to move a ticket (Child node) to another node that will be created. So far I am able to delete the selected ticket. I am just wondering what way would I move the ticket to the new parent node.

The image below is my database structure. I want to move the selected child from Tickets to a new node.

enter image description here

The code below is the code I used to delete the selected ticket. Is there much involved in moving the ticket?

 private void moveDataDialog(final String currentTicketCode ) {
    //alert dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(WalletActivity.this);
    builder.setTitle("Move my Ticket");
    builder.setMessage("Are you sure you want to move  your ticket?");
    //set positive/yes button
    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //user pressed "Yes", delete data


            Query mQuery = mRef.orderByChild("ticketcode").equalTo(currentTicketCode);
            mQuery.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                    for (DataSnapshot ds: dataSnapshot.getChildren()){

                      ds.getRef().removeValue(); // remove values from firebase where ticketCode matches
                   }
                    //show message that post(s) deleted
                    Toast.makeText(WalletActivity.this, "Ticket deleted successfully....", Toast.LENGTH_SHORT).show();
                }
                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {
                    //if anything goes wrong get and show error message
                    Toast.makeText(WalletActivity.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });


        }
    });
Mark_rath
  • 45
  • 7

0 Answers0