Filipe Cruz
Filipe Cruz

Reputation: 91

Kotlin, android, get id from getvalue

I have the following code:

                    for (snapshot in snapshot.children){
                        var viagem = snapshot.getValue()
                        Log.d("teste", viagem.toString())
                       // BuleiaId = viagem
                       // Log.d("teste", BuleiaId.toString())
                       // Log.d("teste", BuleiaId.toString())
                        //your second query with BuleiaId
                    }

That retreives the following output on logcat

{
driveTo=Ponto de Chegada, 
rideDay=Data, 
driveFrom=Ponto de Partida, 
pick3=Ponto de paragem 3, 
pick2=Ponto de paragem 2, 
rideTime=Hora, 
id=6, 
pick1=Ponto de paragem 1, 
user=Filipe
}

How can I change the:

BuleiaId = viagem

to get de id from viagem

Upvotes: 0

Views: 277

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599776

If you want to get the key of the snapshot, that'd be:

var viagem = snapshot.getKey()

If you want to get the value of a specific child property of the snapshot, that'd be:

var viagem = snapshot.child("id").getValue()

Upvotes: 1

Related Questions