-2

I have followed the answer to a question well on the link below on how to create Firestore RecyclerView with database, How to display data from Firestore in a RecyclerView with Android? Now I want to get the items position (I mean document id) of the recyclerView items, I need it in an intent so that I can reference to the particular document in my collections. (In the new activity)

Talkbiz
  • 11
  • 6

1 Answers1

8

The link you have shared is actually an answer from another question not quite a tutorial :) But to answer your question:

Now I want to get the items position (I mean document id)

In order to be able to get the id of the document you are looking for, your adapter class should extend FirestoreRecyclerAdapter class and I think it is, since you are using the code from that answer. So in that case, to get the id of the document you can certainly use the getSnapshots() method like in the following lines of code:

@Override
protected void onBindViewHolder(@NonNull ProductViewHolder holder, int position, @NonNull YourModelClass yourModelClass) {
    String documentId = getSnapshots().getSnapshot(position).getId();
}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193