I am not able to search for a specific string in the database, I was stuck in a problem where i have to search for type of vehicle from users database and show only that information. I tried many solutions on stackoverflow but it was of no use may be because i have a complex structure of database
I know the question is too vague but i have been stuck on this problem for hours so pease help me
I have tried searching for that field by using equalTo and orderby query
Go the truck used by driver using this code
databaseReference1=FirebaseDatabase.getInstance().getReference("truckers").child(userId);
final String[] type_of_truck = new String[1];
databaseReference1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.e("Current Truck",""+dataSnapshot.child("Type of truck").getValue());
type_of_truck[0] = (String) dataSnapshot.child("Type of truck").getValue();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
return type_of_truck[0];
}
Tried to find user using this code
private void findUsers(String type_of_truck) {
DatabaseReference d = FirebaseDatabase.getInstance().getReference("users");
d.orderByChild("type_of_truck").equalTo(type_of_truck).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.e("pp",""+dataSnapshot.getValue());
for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
Log.e("pp",""+userSnapshot.getValue());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
For eg i am using LCV closed body so i should get all information of that delivery id under users reference where type_of_truck is "LCV closed body"