title: Get the userId (or interact with other users) in Firebase Database
body: <p>I am building a chat app with Firebase and I am having issues identifying who is who, when a user sends another user a message, he needs to post it to the receivers node and he needs to know his UID to do that. I need to know how to get the receiver's UID, so I can post directly to his own node. </p>
  
  <p>I tried using <code>intent.putExtra</code> and <code>intent.getExtras</code> from my <code>MainActivity</code> which lists out every user from their directories, this is my current code that does not successfully pass the data I need.</p>
  
  <pre><code> public static class PlaceholderFragment extends Fragment {
  
      private DatabaseReference mDatabase;
      private FirebaseAuth mAuth;
      /**
       * The fragment argument representing the section number for this
       * fragment.
       */
      private static final String ARG_SECTION_NUMBER = "section_number";
  
      public PlaceholderFragment() {
      }
  
      /**
       * Returns a new instance of this fragment for the given section
       * number.
       */
      public static PlaceholderFragment newInstance(int sectionNumber) {
          PlaceholderFragment fragment = new PlaceholderFragment();
          Bundle args = new Bundle();
          args.putInt(ARG_SECTION_NUMBER, sectionNumber);
          fragment.setArguments(args);
          return fragment;
      }
  
      public static class UserHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
          View mView;
  
  
          public UserHolder(View itemView) {
              super(itemView);
              itemView.setOnClickListener(this);
              mView = itemView;
          }
  
          public void setName(String name) {
              TextView field = (TextView) mView.findViewById(R.id.thename);
              field.setText(name);
          }
  
  
          public void setImage(String image){
              ImageView pp = (ImageView) mView.findViewById(R.id.imageurl);
              try{
                  Picasso.with(Application.getAppContext()).load(image).placeholder(R.drawable.nodp).error(R.drawable.nodp).transform(new CircleTransform()).into(pp);
              }
              catch (IllegalArgumentException e){
                  Picasso.with(Application.getAppContext()).load(R.drawable.nodp).transform(new CircleTransform()).into(pp);
              }
          }
  
  
          @Override
          public void onClick(View mView) {
  
  
              //what to do here
          }
  
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_main, container, false);
          TextView textView = (TextView) rootView.findViewById(R.id.section_label);
          //textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
  
  
  
          //private static final String TAG = "UserListActivity";
  
  
              //final TextView name = (TextView) rootView.findViewById(R.id.lastname) ;
              //final ImageView profileImage = (ImageView) rootView.findViewById(R.id.imageView4);
              mAuth = FirebaseAuth.getInstance();
              FirebaseUser user = mAuth.getCurrentUser();
  
              final DatabaseReference root = FirebaseDatabase.getInstance().getReference();
              DatabaseReference userRef = root.child("users");
  
  
  
              RecyclerView recycler = (RecyclerView) rootView.findViewById(R.id.recyclerview3);
              recycler.setHasFixedSize(true);
              recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
  
  
  
              FirebaseRecyclerAdapter mAdapter = new FirebaseRecyclerAdapter&lt;UserList, UserHolder&gt;(UserList.class, R.layout.userlistrow, UserHolder.class, userRef) {
                  @Override
                  public void populateViewHolder(UserHolder userViewHolder, final UserList userList, final int position) {
  
                      //try catch block to catch events of no posts, it will most likely return a null error, so im catching it, else
                      //find its exception and catch it
                      try {
  
                          String firstname = userList.getFirstname().toString();
                          String lastname = userList.getLastname().toString();
                          firstname = firstname.substring(0, 1).toUpperCase() + firstname.substring(1); //convert first string to uppercase
                          lastname = lastname.substring(0, 1).toUpperCase() + lastname.substring(1);// same thing happening here
                          String name = (firstname + " " + lastname); // concatenate firstname and lastname variable.
                          userViewHolder.setName(name);
  
  
  
                      }
                      catch(NullPointerException e) {
  
                          String firstname = "Not";
                          String lastname = "set";
                          String name = (firstname + " " + lastname );
                          userViewHolder.setName(name);
  
  
                      }
                      catch (StringIndexOutOfBoundsException e) {
  
                          String firstname = "No";
                          String lastname = "name";
                          String name = (firstname + " " + lastname );
                          userViewHolder.setName(name);
  
                      }
  
                      //note that picasso view holder was applied in the view holder instead
                      //String image = userList.getImgUrl().toString();
                      //userViewHolder.setImage(image);
                      //findViewById(R.id.progressBar3).setVisibility(View.GONE);
  </code></pre>
  
  <p>This is where I am passing the extras, and it doesnt seem to work</p>
  
  <pre><code>                    userViewHolder.mView.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              //Log.w(TAG, "You clicked on "+position);
                              //String firstname = userList.getFirstname();
                              //String lastname = userList.getLastname();
                              //firstname = firstname.substring(0, 1).toUpperCase() + firstname.substring(1); //convert first string to uppercase
                              //lastname = lastname.substring(0, 1).toUpperCase() + lastname.substring(1);// same thing happening here
                              //String name = (firstname + " " + lastname); // concatenate firstname and lastname variable.
  
                              Intent intent = new Intent(getActivity(), Userdetail.class); //change to onclick
                              intent.putExtra("userId", userList.getUserId());//you can name the keys whatever you like
                              intent.putExtra("lastname", userList.getLastname().toString());
                              intent.putExtra("firstname", userList.getFirstname().toString());
                              intent.putExtra("image", userList.getImgUrl().toString()); //note that all these values have to be primitive (i.e boolean, int, double, String, etc.)
                              startActivity(intent);
  
                          }
                      });
  
                  }
  
  
              };
              recycler.setAdapter(mAdapter);
  
  
          return rootView;
      }
  }
  </code></pre>
  
  <p>If you need more information, please ask in the comments. Ive googled around but no help</p>
  
  <pre><code>package com.mordred.theschoolapp;
  
  import com.google.firebase.database.IgnoreExtraProperties;
  
  /**
   * Created by mordred on 11/28/16.
   */
  public class UserList {
      public String firstname;
      public String lastname;
      public String userId;
      public String imgUrl;
  
  public UserList() {
      // Default constructor required for calls to DataSnapshot.getValue(User.class)
  }
  
  public String getFirstname() {
      return firstname;
  }
  
  public void setFirstname(String firstname) {
      this.firstname = firstname;
  }
  
  public String getLastname() {
      return lastname;
  }
  
  public void setLastname(String lastname) {
      this.lastname = lastname;
  }
  
  public String getImgUrl() {
      return imgUrl;
  }
  
  public void setImgUrl(String imgUrl) {
      this.imgUrl = imgUrl;
  }
  
  public String getUserId() {
      return userId;
  }
  
  public void setUserId(String userId) {
      this.userId = userId;
  }
  </code></pre>
  
  <p>}</p>