我想将票证(子节点)移动到将要创建的另一个节点。到目前为止,我已经能够删除所选票证。我只是想知道如何将故障单移到新的父节点。
下图是我的数据库结构。我要将选定的孩子从“票证”移动到新节点。
下面的代码是我用来删除所选票证的代码。运送车票有很多事情吗?
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();
}
});
}
});