title: How to retrieve data from one single userID Firebase Android
body: <p>In my firebase database, I have list of users that have different information under them. I would like to retrieve information from a single userId, which I will define in the code and I want to only get information from that user.</p>
  
  <p>My data looks like;</p>
  
  <pre><code>UserTable
  {
    "fmXWU324VHdDb8v6h7gvNjRojnu33" : {
      "-KbJtw467nl6p253HZ537" : {
        "Name" : "name1",
        "Email" : "something1@something.com",
        "userid" : "fmXWU324VHdDb8v6h7gvNjRojnu33"
      }
    },
    "pJtC45fW0MMi352UiPWnWdIS7h88" : {
      "-Kb012ls9iMnzEL723o9I" : {
        "Name" : "name2",
        "Email" : "something2@something.com",
        "userid" : "pJtC45fW0MMi352UiPWnWdIS7h88"
      },
      "-Kb0aq0q25FJq38256SrC" : {
        "Name" : "name3",
        "Email" : "something3@something.com",
        "userid" : "pJtC45fW0MMi352UiPWnWdIS7h88"
      },
      "-Kb0atopfK64F6jy124Qi1u" : {
        "Name" : "name3",
        "Email" : "something1@something.com",
        "userid" : "pJtC45fW0MMi352UiPWnWdIS7h88"
    }
  } 
  </code></pre>
  
  <p>and I want to, say for example read and display all data from this user <code>"fmXWU324VHdDb8v6h7gvNjRojnu33"</code>. I am not sure how I can do that. I tried this, which seems logical but it doesn't seem to work:</p>
  
  <pre><code>df.child("UserTable").child(user.getUid())).addChildEventListener(new ChildEventListener()
  </code></pre>
  
  <p>it gives this error:</p>
  
  <pre><code>Can't convert object of type java.lang.String to type com.android.example.UserTable
  </code></pre>
  
  <p>In addition, I have tried:</p>
  
  <pre><code>df.child("UsersTable").child("userid").child(user.getUid()).ad‌​dChildEventListener(‌​new ChildEventListener() 
  </code></pre>
  
  <p>I can seem to figure out what I am doing wrong, as what I have tried seems logical and should work. Please can someone help me out.</p>
  
  <p>EDITED:</p>
  
  <pre><code>public ArrayList&lt;data&gt; get(String userID){
  
        df.child("UsersTable").child(userID).ad‌​dChildEventListener(‌​new ChildEventListener()  {
      @Override
      public void onChildAdded(DataSnapshot dataSnapshot, String s) {
          fetch(dataSnapshot);
      }
  
      @Override
      public void onChildChanged(DataSnapshot dataSnapshot, String s) {
          fetch(dataSnapshot);
      }
  
      @Override
      public void onChildRemoved(DataSnapshot dataSnapshot) {
  
      }
  
      @Override
      public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
      }
  
      @Override
      public void onCancelled(DatabaseError databaseError) {
  
      }
  });
  
  return data;
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <pre><code>private void fetchData(DataSnapshot dataSnapshot)
  {
  
      for (DataSnapshot ds : dataSnapshot.getChildren())
      {
          Userdetail userdetail =ds.getValue(Userdetail.class);
          userdetails.add(userdetail );
      }
  }
  </code></pre>