且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RecyclerView上的删除按钮删除错误的项目

更新时间:2023-12-03 13:10:52

要从数据库中删除特定文档,您需要知道其ID.因此,这意味着当用户单击要删除的项目时,您将需要能够查找该项目的文档ID.因此,创建视图时,您需要同时从文档及其ID中获取值.

To delete a specific document from the database you'll need to know its ID. So that means when the user clicks on an item to delete, you'll need to be able to look up that item's document ID. For that reason you'll need to get both the values from the document and its ID when you're creating the view.

因此,除了 RewardModel 对象之外,您还需要将相应的文档ID保留在某处.

So in addition to the RewardModel objects, you'll also need to keep the corresponding document IDs somewhere.

如果您使用FirebaseUI显示列表,则可以通过以下操作获取给定位置的ID:

If you're using FirebaseUI to show the list, you can get the ID for a given position by following: Is there a way to get document ID of item from FirestoreRecyclerAdapter?