Reputation: 1
Can anyone please help? I'm stuck, can't retrieve simple data. This is my code:
And this is my database:
Upvotes: 0
Views: 80
Reputation: 138824
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:
Upvotes: 1