从addChildEventListener调用以下函数,以便在需要时从我的Firebase数据库中删除特定节点。 这里的问题是函数启动“删除项目”。表示任务已成功执行,但该节点保持在数据库上。Android - 关于从Firebase数据库中删除节点的问题
有人能告诉我什么是错的?
private void showData(DataSnapshot ds) {
String keyValue = null;
if(ds.hasChildren()) {
keyValue = ds.getKey();
Toast.makeText(getActivity().getApplicationContext(), "Removing item...", Toast.LENGTH_SHORT).show();
ds.getRef().child(keyValue).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(getActivity().getApplicationContext(), "Item removed.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity().getApplicationContext(), "Something bad happened while removing item.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
编辑 如果有帮助,我的查询如下:
orderItemsByTime = db.getInstance().getReference().child("items").orderByChild("time");
你试图删除'.getRef()'当你'addOnCompleteListener'? –
做到了。不幸的是,没有工作。 –