1
Good morning ! Guys, I have a situation in which I want to return in a list all the data whose one of the children are equal to id, in the image below I have the nodes structures of my database in firebase and I want to return for example the number of all activities whose one of the nodes (idUsuario) be the same as the logged-in user (in case I used a form of encryption to store the user id and the id I can recover normally), to improve, in a relational database would look something like this: select * from activities Where idUsuario = "A" for example;
Well, to solve this problem I changed the structure I was using to save the data in firebase so it would look like this:
This way I can bring more easily the data that is tied to the indicated user:
//Evento de consulta
valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//LIMPANDO A LISTA
atividadeArrayList.clear();
//Listando cada uma das atividades criadas pelo usuário
for (DataSnapshot dados: dataSnapshot.getChildren()){ //recupera os filhos do nó principal
Atividade atividade = dados.getValue(Atividade.class);
atividadeArrayList.add(atividade);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
But thank you Matheus for your help !
Matheus, I’m testing your code here, but I’m having a doubt, in case you requested your Movie class as Movie, but I got confused, you can explain to me the following code logic: String id = dataSnapshot.getValue(Movie.class); if (Movie.getLead().equals('xxxxxxxxprofile')) { console.log(querySnapshot.getKey()); }
– Eduardo Rafael Moraes
I had taken an example that I used, and had not completely customized, I apologize. So the Myclass, are say the values you implemented in firebase understand? With getValue you can race them
– Dev
This link would be a perfect reference for you to have a look at: https://stackoverflow.com/questions/42950532/android-extracting-data-from-firebase-data-snapshot concerteza irá ajudar muito em suas dúvidas
– Dev
Well, I changed my mind and hit the bank to stay that way : +ACTIVITIES + idUsuario('xxxxxxxxxxperfil') + idAtivity + Description + title + time + id + idUsuario ...
– Eduardo Rafael Moraes
Maravilha Eduardo
– Dev