skip to Main Content

I have tried using the following if statement, but the only values that it returns are the URL for my image link:

my database

reference.child("Businesses").child(firebaseUser.getUid()).addValueEventListener(new ValueEventListener() {

  @Override
  public void onDataChange(@NonNull DataSnapshot snapshot) {

    if (snapshot.exists())
    {
        String businessName = snapshot.getValue().toString();
        editTextBusinessName.setText(businessName);

        String businessAbout = snapshot.getValue().toString();
        editTextAbout.setText(businessAbout);

        String businessAddress = snapshot.getValue().toString();
        editTextAddress.setText(businessAddress);

        String businessContactPerson = snapshot.getValue().toString();
        editTextContactPerson.setText(businessContactPerson);

        String businessContactNumber = snapshot.getValue().toString();
        editTextContactNumber.setText(businessContactNumber);
    }

2

Answers


  1. Chosen as BEST ANSWER

    I am not sure if this was the right way to solve my problem, but it worked : My database structure was Businesses -> userID -> businessName -> businessAbout. I changed it so all the children will fall under just userID, that included businessName.

    Thank you guys :)


  2. If your firebaseUser.getUid() returns NN3ikr..., then your onDataChange should already be called with the correct snapshot according to your screenshot.

    You can get the values of the individual properties with:

    reference.child("Businesses").child(firebaseUser.getUid()).addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(@NonNull DataSnapshot snapshot) {
        if (snapshot.exists()) {
            String businessAbout = snapshot.child("businessAbout").getValue(String.class);
            String businessAddress = snapshot.child("businessAddress").getValue(String.class);
            String businessContactPerson = snapshot.child("businessContactPerspon").getValue(String.class);
            ...
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search