簡體   English   中英

如何在 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();
    });

}

我收到了成功消息,但是當我看到數據庫時,它並沒有被刪除。

並且如果您知道如何刪除文檔,則可以根據您的答案發布。

編輯!

在此處輸入圖像描述

如果刪除該文檔,我還如何刪除存儲在我的 Firebase 存儲中的圖像。

因為如果我能夠刪除該文檔,那么我該如何處理該圖像,所以我想從我的 Firebase 存儲數據庫中刪除該圖像,我該怎么做?

當您使用以下代碼行時:

String id = colRef.document().getId();

這意味着您正在生成一個新的文檔 ID。 當涉及到刪除操作時,您應該在document()調用中指定現有文檔 ID:

colRef.document(id).delete().addOnCompleteListener(/* ... /*);

如果您不將該 ID 存儲在任何地方,那么您應該考慮將其存儲為文檔的屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM