title: How to iterate over RecyclerView items
body: <p>In my app i have a RecyclerView with a simple item view that consists of a TextView and a Spinner in each row.</p>
  
  <p>After the user clicks "Save" from the action bar, i need to iterate over all the items and get the Spinner selected value.</p>
  
  <p>Any ideas how this can or should be achieved?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have managed to iterate using the following loop, but is it a good solution calling findViewById() for every row since it's a heavy function to call performance wise?</p>
  
  <pre><code>for (int i = 0; i &lt; rvAttendanceItems.getChildCount(); i++) {
      Spinner spinner = (Spinner) rvAttendanceItems.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.attendance_list_status);
      spinner.getSelectedItemId();
  }
  </code></pre>
  
  <p>My full RecyclerView code:</p>
  
  <pre><code>public class AttendanceAdapter extends RecyclerView.Adapter&lt;AttendanceAdapter.AttendanceViewHolder&gt; {
  
      private List&lt;Student&gt; studentItems;
      private Fragment frag;
      ArrayList&lt;Status&gt; statuses = new ArrayList&lt;&gt;();
  
      public AttendanceAdapter(List&lt;Student&gt; studentItems, Fragment frag) {
          this.studentItems = studentItems;
          this.frag = frag;
  
          DbHelper db = DbHelper.getInstance(frag.getContext());
          Cursor c = db.getStatuses("attendance");
  
          if (c != null) {
              while (c.moveToNext()) {
                  Status tempStatus = new Status(c.getInt(c.getColumnIndex(DbHelper.STATUS_ID)), c.getInt(c.getColumnIndex(DbHelper.STATUS_COLOR)), c.getString(c.getColumnIndex(DbHelper.STATUS_DESC)), c.getString(c.getColumnIndex(DbHelper.STATUS_CATEGORY)));
                  statuses.add(tempStatus);
              }
              c.close();
          } else {
              Toast.makeText(frag.getContext(), "Could not retrieve status list", Toast.LENGTH_SHORT).show();
          }
      }
  
      @Override
      public AttendanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_attendance, parent, false);
          return new AttendanceViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(final AttendanceViewHolder holder, int position) {
  
          final Student current = studentItems.get(position);
  
          SpinnerAdapter adapter = new SpinnerAdapter(frag.getContext(), R.layout.item_spinner_status, statuses);
  
          holder.sStatus.setAdapter(adapter);
          holder.tvName.setText(current.getFullName());
      }
  
      @Override
      public int getItemCount() {
          return studentItems.size();
      }
  
      public class AttendanceViewHolder extends RecyclerView.ViewHolder {
  
          private final TextView tvName;
          private final Spinner sStatus;
  
          public AttendanceViewHolder(View itemView) {
              super(itemView);
  
              tvName = (TextView) itemView.findViewById(R.id.attendance_list_name);
              sStatus = (Spinner) itemView.findViewById(R.id.attendance_list_status);
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
                      sStatus.performClick();
                  }
              });
          }
      }
  }
  </code></pre>