Mikimouche
Mikimouche

Reputation: 51

Get document identifier, Firestore

I'm trying to get the ID of my fields. But when I click on the elements of my listview, it shows me identifiers that does not exist in the database and changes to each click.

Database: Database

Display:

Display enter image description here

Code: Code

How can I get the id of the address selected in the listview?

Upvotes: 2

Views: 125

Answers (1)

Bruno Galvão
Bruno Galvão

Reputation: 57

So, where is Geneva put what you want.

Inside onClick PositiveButton:

    db.collection("Adresse").whereEqualTo("Adresse", "Geneva").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {

            if (e != null) {
                Log.w(TAG, "listen:error", e);
                return;
            }

            for (DocumentChange dc : queryDocumentSnapshots.getDocumentChanges()) {

                String docid = dc.getDocument().getId();
                Toast.makeText(getApplicationContext(), docid, Toast.LENGTH_SHORT).show();
            }

        }
    });

Upvotes: 1

Related Questions