如何在 android 的回收站视图中从 firestore 中删除文档
How to delete document from firestore in recycler view in android
如何在 android 的 recyclerView 中从 Firestore 中删除文档。
我有自动生成的文档 ID 我想删除那个自动生成的 ID 的数据
我试过了,但没用
private void removeData() {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.setMessage("Deleting this item...");
dialog.show();
CollectionReference colRef firestore.collection("topic");
String id = colRef.document().getId();
colRef.document(id).delete().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Toast.makeText(PracticeActivity.this, "Deleted Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(PracticeActivity.this, "Unable to delete!", Toast.LENGTH_SHORT).show();
Log.d("Firebase", "onComplete: Error Unable to delete : " + task.getException());
}
dialog.dismiss();
});
}
我收到了成功消息,但是当我看到数据库时,它并没有被删除。
如果你知道如何删除文档,那么你可以post根据你的答案。
已编辑!
如果我删除了该文档,我还如何删除存储在我的 Firebase 存储中的图像。
因为如果我能够删除该文档,那么我该如何处理该图像,所以我想从我的 Firebase 存储数据库中删除该图像,我该怎么做?
当您使用以下代码行时:
String id = colRef.document().getId();
这意味着您正在生成一个新的文档ID。当涉及到删除操作时,您应该在 document()
调用中指定现有文档 ID:
colRef.document(id).delete().addOnCompleteListener(/* ... /*);
如果您不将该 ID 存储在任何地方,那么您应该考虑将其存储为文档的 属性。
如何在 android 的 recyclerView 中从 Firestore 中删除文档。
我有自动生成的文档 ID 我想删除那个自动生成的 ID 的数据
我试过了,但没用
private void removeData() {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.setMessage("Deleting this item...");
dialog.show();
CollectionReference colRef firestore.collection("topic");
String id = colRef.document().getId();
colRef.document(id).delete().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Toast.makeText(PracticeActivity.this, "Deleted Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(PracticeActivity.this, "Unable to delete!", Toast.LENGTH_SHORT).show();
Log.d("Firebase", "onComplete: Error Unable to delete : " + task.getException());
}
dialog.dismiss();
});
}
我收到了成功消息,但是当我看到数据库时,它并没有被删除。
如果你知道如何删除文档,那么你可以post根据你的答案。
已编辑!
如果我删除了该文档,我还如何删除存储在我的 Firebase 存储中的图像。
因为如果我能够删除该文档,那么我该如何处理该图像,所以我想从我的 Firebase 存储数据库中删除该图像,我该怎么做?
当您使用以下代码行时:
String id = colRef.document().getId();
这意味着您正在生成一个新的文档ID。当涉及到删除操作时,您应该在 document()
调用中指定现有文档 ID:
colRef.document(id).delete().addOnCompleteListener(/* ... /*);
如果您不将该 ID 存储在任何地方,那么您应该考虑将其存储为文档的 属性。