title: How can I return data from a RecyclerView adapter?
body: <p>I have a <code>RecyclerView</code> in which in each object of the <code>RecyclerView</code> I have a checkbox. Each time one of the checkboxes is pressed I would like to insert data on the Adapter. One time I finished (press a button on the Fragment that sets the <code>Adapter</code> to the <code>RecyclerView</code>) the data have to be returned.</p>
  
  <p>My code(simplified) of the <code>Adapter</code> of the <code>RecyclerView</code> is:</p>
  
  <pre><code>public List&lt;CarItem&gt; data; 
  public class MyCustomAdapter extends RecyclerView.Adapter&lt;MyCustomAdapter.MyCustomViewHolder&gt;  {
  
      public MyCustomAdapter(List&lt;CarItem&gt; data) {
          this.data=data;
      }
  
      public MyCustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view= LayoutInflater.from(parent.getContext()).inflate(R.layout_car_item, parent, false);
          return new MyCustomViewHolder(view);
      }
  
      public void onBindViewHolder(final MyCustomViewHolder holder, final int position) {
          holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                         //Here I add the data that I want to store
                         holder.getItem();
                    }
              });
      }
  
      public class MyCustomViewHolder extends RecyclerView.ViewHolder{
            public MyCustomViewHolder (View itemView) {
                super(itemView);
                //Here I make reference to all the elements of the layout of the Adapter
            }
  
            public void getItem(){
                Log.d("prove", "" + data.size());
            }
      }
  }
  </code></pre>
  
  <p>I have created <code>getItem()</code> method to get the data inside <code>MyCustomViewHolder</code> but I do not know how to return the data to the <code>Fragment</code> in which I sets the <code>Adapter</code> to the <code>RecyclerView</code>.</p>
  
  <p>Is there some way to return data from the <code>Adapter</code> of the <code>RecyclerView</code> to the <code>Fragment</code> in which I set it?</p>
  
  <p>Thanks in advance!</p>