Question:
I have a database like this:
{
"message" : "Hello, World!",
"reserva" : [ null, {
"codreserva" : 123,
"email" : "teste@teste.com",
"status" : "check in"
}, {
"codreserva" : 124,
"email" : "fabio@ciaf.com.br",
"status" : "check out"
} ]
}
And I have a code to look up the booking status:
public void ProcuraReserva(String codigodareserva){
// Read from the database
myRef = database.getReference("reserva/"+codigodareserva+"/status");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
textview1.setText("Status da reserva "+ value);
}
@Override
public void onCancelled(DatabaseError error) {
textview1.setText("Status com falha");
}
});
}
However, he searched my reservation ID
and wanted him to search according to CODRESERVA
. Could someone help me in this question searching according to my "line" in this Firebase
database.
Answer:
Try using child()
myRef.child("codreserva").child(codigoreserva).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
textview1.setText("Status da reserva "+ value);
}
@Override
public void onCancelled(DatabaseError error) {
textview1.setText("Status com falha");
}