If you want to read the value of the name field that exists in the objects in the Domains node, then you should create a reference that points to that node and perform a get() call, as seen in the following lines of code:
DatabaseReference db = FirebaseDatabase.getInstance().getReference();
DatabaseReference domainsRef = db.child("Domains");
domainsRef.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (task.isSuccessful()) {
for (DataSnapshot ds : task.getResult().getChildren()) {
String name = ds.child("name").getValue(String.class);
Log.d("TAG", name);
}
} else {
Log.d("TAG", task.getException().getMessage()); //Never ignore potential errors!
}
}
});
2
Answers
I guess you want to get the Id of the object at a specific index (like your want to find the id where name is web (just an example))
try the below piece of code
If you want to read the value of the
name
field that exists in the objects in theDomains
node, then you should create a reference that points to that node and perform aget()
call, as seen in the following lines of code:The result in the logcat will be: