Delete button on RecyclerView deletes the wrong item

前端 未结 2 1165
遥遥无期
遥遥无期 2021-01-28 10:27

I am using Firestore adapter for my RecyclerView and I am having trouble with the \'Delete\' button. When I press it, it deletes the wrong item instead of the one t

相关标签:
2条回答
  • 2021-01-28 11:11

    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.

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

    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?

    0 讨论(0)
  • 2021-01-28 11:25

    You are sending wrong data.

    Query query = collectionReference.whereEqualTo("donationReq", (position + 1));
    

    You had write position instead of position + 1

    0 讨论(0)
提交回复
热议问题