'On Android, how do you get the data from an email address in Firebase, then access the child, and from there you access the other Firebase data?

The following file explains better what I really mean. It's a screenshot of data sent from a dummy user in Firebase:

enter image description here

The code:

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users");
                // ref.addValueEventListener(new ValueEventListener() {
                ref.orderByChild("Email").equalTo("[email protected]").addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        for (DataSnapshot datas : dataSnapshot.getChildren()) {
                            String key = datas.getKey();
                            DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(key);
                            Toast.makeText(getApplicationContext(), key, Toast.LENGTH_LONG).show();
                            ref.addValueEventListener(new ValueEventListener() {
                                @Override
                                public void onDataChange(@NonNull DataSnapshot snapshot) {
                                    String name = dataSnapshot.child("Name").getValue().toString();
                                    String state = dataSnapshot.child("State").getValue().toString();
                                    String stateRegion = dataSnapshot.child("StateRegion").getValue().toString();
                                    String telephone = String.valueOf(dataSnapshot.child("Telephone").getValue());
                                    nameEditText.setText(name);
                                    stateEditText.setText(state);
                              stateRegionEditText.setText(stateRegion);     
                               telephoneEditText.setText(telephone);
                                }
                                @Override
                                public void onCancelled(@NonNull DatabaseError error) {
                                }
                            });
                        }
                    }
                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {
                    }
                });
            }
        });

Please, can some person help?

More information about data stored in the Firebase:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source