0

Can anyone please help? I'm stuck, can't retrieve simple data. This is my code:

enter image description here

And this is my database:

enter image description here

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Saami
  • 1
  • 1

1 Answers1

1

Assuming that the seller note, is a direct child of your database root, to get the value of your userType property, please use the following lines of code:

String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference userTypeRef = rootRef.child("seller").child(uid).child("BasicInfo").child("userType");
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        String userType = dataSnapshot.getValue(String.class);
        Log.d("TAG", userType);

        if(userType.equals("buyer")) {
            //Your logic
        }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        Log.d("TAG", databaseError.getMessage()); //Don't ignore errors!
    }
};
userTypeRef.addListenerForSingleValueEvent(valueEventListener);

Please note that logic regarding the value you get from the database is placed inside the callback because Firebase API's are asynchronous. For more information, please also see my answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193