title: Retrieve the values from Firebase and display in EditText
body: <p>So I am trying to retrieve user profile information from my firebase database to display it on my Android app but it does not seem to work at all!</p>
  
  <p>Here is the code I tried with but no luck at all!</p>
  
  <pre><code>package com.example.ravneet.bloodhub;
  
  import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.TextView;
  
  import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.database.ChildEventListener; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase;
  
  import java.util.ArrayList;
  
  public class Editprofile extends AppCompatActivity {
      TextView chngpsw;
      EditText name, state, city, bloodgrp, mobileno, email;
      FirebaseUser currentFirebaseUser;
      String id;
      private static final String TAG = "EditProfile";
      ArrayList&lt;String&gt; mylist;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_editprofile);
          mylist  = new ArrayList&lt;String&gt;();
          chngpsw = (TextView) findViewById(R.id.chngpsw);
          currentFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
          id = currentFirebaseUser.getUid();
          setTitle("Edit Profile");
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          name = (EditText) findViewById(R.id.name);
          state = (EditText) findViewById(R.id.state);
          city = (EditText) findViewById(R.id.city);
          bloodgrp = (EditText) findViewById(R.id.bloodgrp);
          mobileno = (EditText) findViewById(R.id.mobileno);
          email = (EditText) findViewById(R.id.email);
          chngpsw.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent i = new Intent(getApplicationContext(), Changepswrd.class);
                  startActivity(i);
              }
          });
          readData();
          if(mylist.size() != 0){
              setvalues();
          }
          //Log.d(TAG, "SIZE IS on Create " + mylist.size());
      }
  
      private void readData() {
  
          DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(id);
         // Log.d(TAG, "UserID is " + id);
          ref.addChildEventListener(new ChildEventListener() {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                 fetchdata(dataSnapshot);
  
              }
  
              @Override
              public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                  fetchdata(dataSnapshot);
              }
  
              @Override
              public void onChildRemoved(DataSnapshot dataSnapshot) {
  
              }
  
              @Override
              public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
          Log.d(TAG, "Bottom Size :   " + mylist.size());
  
      }
      private void fetchdata(DataSnapshot dataSnapshot){
          String value = dataSnapshot.getValue(String.class);
          //Log.d(TAG, "Value is " + value);
          mylist.add(value);
          Log.d(TAG, "Size :   " + mylist.size());
      }
      private void setvalues(){
          bloodgrp.setText(mylist.get(0));
          city.setText(mylist.get(1));
          email.setText(mylist.get(2));
          mobileno.setText(mylist.get(3));
          name.setText(mylist.get(4));
          state.setText(mylist.get(5));
      } }
  </code></pre>
  
  <p>When i tried to print a size of arraylist in oncreate method it shows 0
  here is what it shows in logcat</p>
  
  <pre><code>&gt; D/EditProfile: UserID is MkfeHsMuJyaNr5Be8R7eRojHngE2 09-24
  &gt; D/EditProfile: Bottom Size :   0 
  &gt; D/EditProfile: Size :   1
  &gt; D/EditProfile: Size :   2 
  &gt; D/EditProfile: Size :   3
  &gt; D/EditProfile: Size :   4 
  &gt; D/EditProfile: Size :   5
  &gt; D/EditProfile: Size :   6
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/zndPf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zndPf.png" alt="Here is Firebase Database"></a></p>
  
  <p>Here is Firebase Database</p>