title: Setting data on ViewHolder
body: <p>I am using a RecyclerView in my project and I am having an issue where my RecyclerView is being populated by the same values as if the values are being overwritten inside the <code>forEach</code> in <code>onBindViewHolder</code> below:</p>
  
  <pre><code>   class ProfListAdapter extends RecyclerView.Adapter&lt;ViewHolder&gt;{
      private LayoutInflater mLayoutInflater;
      public ProfListAdapter(Context context) {
          mLayoutInflater = LayoutInflater.from(context);
      }
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType){
          return new ViewHolder(mLayoutInflater
          .inflate(R.layout.recycler_view, viewGroup, false));
      }
  
  
      @Override
      public void onBindViewHolder(ViewHolder viewHolder, final int position){
      System.out.println(position);
          final String profName;
          Integer k = 0;
          for (Integer key : mData.keySet()) {
              viewHolder.setData(mData.get(key));
          }
  
  
      viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v){
              Intent intent = ProfPager.newIntent(getActivity(), position);
              startActivity(intent);
          }
      });
      }
      @Override
      public int getItemCount() {
      return mData.size();
  }
  }
  
  class ViewHolder extends RecyclerView.ViewHolder {
      private TextView mTextView;
      private ViewHolder(View itemView){
          super(itemView);
          mTextView = (TextView) itemView.findViewById(R.id._prof); // galleryimage
      }
      private void setData(String profName){
          mTextView.setText(profName);
          System.out.println("setData" + profName);
      }
  }
  </code></pre>
  
  <p>When I log out to the console I can see that the value in <code>setData()</code> is getting the correct item to display. However, what is being displayed inside the fragment is just the last <code>profName</code> that is comes across in the <code>forEach</code>. What could be causing this behaviour? Here is a link to the entire <code>fragment</code>: <a href="https://pastebin.com/xS7CSbbK" rel="nofollow noreferrer">https://pastebin.com/xS7CSbbK</a></p>
  
  <p>If I use the <code>position</code>, it does not always coincide with the key in the <code>Hashmap</code> that stores the <code>SQLite</code> <code>_id</code>. </p>