title: Click an ImageButton which belongs to a CardView inside a RecyclerView
body: <p><strong>SOLVED</strong></p>
  
  <p>I've fixed it mixing your answers, so I've decided to write down on here.</p>
  
  <p>The key has been the <code>ViewHolder</code> constructor:</p>
  
  <p>I have deleted the <code>setOnClickListener()</code> and the <code>onClick()</code> methods and I´ve defined this inner class in my <code>ObjectAdapter.java</code>.</p>
  
  <pre><code>public static class ViewHolder extends RecyclerView.ViewHolder{
  
       public ViewHolder(View itemView) {
              super(itemView);
              card_first_btn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      int position = getAdapterPosition();
                      Toast.makeText(v.getContext(), object.get(position).getName(), Toast.LENGTH_SHORT).show();
                  }
              });
              card_second_btn.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      Toast.makeText(v.getContext(), "Forward button", Toast.LENGTH_SHORT).show();
                  }
              });
       }
  }
  </code></pre>
  
  <p>And that´s all. The rest of the class is the same.</p>
  
  <p>The <code>ObjectFragment.java</code> is:</p>
  
  <pre><code>public class ObjectFragment extends Fragment {
  
      public void ObjectFragment() {
          // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
          // Inflate the layout for this Fragment
          return layoutInflater.inflate(R.layout.fragment_object, container, false);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          final ArrayList&lt;Object&gt; objects = initializeList();
  
          if(!objects.isEmpty()) {   
              RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.objects_recyclerView);
              recyclerView.setHasFixedSize(true);
              recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
              recyclerView.setItemAnimator(new DefaultItemAnimator());
              recyclerView.addItemDecoration(new SimpleDivider(getActivity().getApplicationContext()));
  
              final ObjectAdapter objectAdapter = new ObjectAdapter(objects, R.layout.card_object);    
              recyclerView.setAdapter(objectAdapter);
          }
      }
  
      private ArrayList&lt;Object&gt; initializeList() {
          ArrayList&lt;Object&gt; objects= new ArrayList&lt;&gt;();    
          objects.add(new Object(...));    
          return objects;
      }
  }
  </code></pre>
  
  <p>Thank you very much guys.</p>
  
  <hr>
  
  <p><strong>Original question</strong></p>
  
  <p>I have a <code>RecyclerView</code> which contains some <code>CardViews</code>. This <code>CardViews</code> have two different <code>ImageButton</code> which make different things when you click them (obvious).</p>
  
  <p>Here is the <code>card_object.xml</code></p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/object_card"
      card_view:cardCornerRadius="2dp"
      card_view:cardElevation="2dp"
      card_view:cardBackgroundColor="@color/colorPrimary"
      android:clickable="true"&gt;
  
      &lt;LinearLayout
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          android:orientation="vertical"
          android:background="@color/colorPrimary"&gt;
  
          &lt;ImageButton
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:id="@+id/object_card_first_button"
                  android:src="@drawable/contact_100px"
                  android:maxHeight="25dp"
                  android:maxWidth="25dp"
                  android:adjustViewBounds="true"
                  android:scaleType="centerCrop"
                  android:background="@color/transparentBackgroundPrimary"
                  android:layout_marginRight="54dp"
                  android:layout_marginEnd="54dp"/&gt;
  
          &lt;ImageButton
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:src="@drawable/forward_100px"
                  android:maxHeight="25dp"
                  android:maxWidth="25dp"
                  android:adjustViewBounds="true"
                  android:scaleType="centerCrop"
                  android:background="@color/transparentBackgroundPrimary"
                  android:id="@+id/object_card_second_button" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>This is the main code of my <code>ObjectAdapter.java</code>:</p>
  
  <pre><code>public class ObjectAdapter 
          extends RecyclerView.Adapter&lt;ObjectAdapter.ViewHolder&gt; 
          implements View.OnClickListener {
  
      private ArrayList&lt;Object&gt; objects;
      private int itemLayout;
      private View.OnClickListener onClickListener;
  
      public ObjectAdapter(ArrayList&lt;Object&gt; objects, int itemLayout) {
          this.objects = objects;
          this.itemLayout = itemLayout;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          View view = LayoutInflater.from(viewGroup.getContext())
                  .inflate(itemLayout, viewGroup, false);
  
          view.setOnClickListener(this);
  
          return new ViewHolder(view);
      }
  
      public void setOnClickListener(View.OnClickListener listener) {
          this.onClickListener = listener;
      }
  
      public void onClick(View view) {
          if(onClickListener != null) {
          onClickListener.onClick(view);
      } 
  }
  </code></pre>
  
  <p>My <code>ObjectFragment.java</code> is the next:</p>
  
  <pre><code>public class ObjectFragment extends Fragment {
  
      public void ObjectFragment() {
          // Required empty public constructor
      }
  
      @Override
      public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
          // Inflate the layout for this Fragment
          return layoutInflater.inflate(R.layout.fragment_object, container, false);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          final ArrayList&lt;Object&gt; objects = initializeList();
  
          if(!objects.isEmpty()) {   
              RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.objects_recyclerView);
              recyclerView.setHasFixedSize(true);
              recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
              recyclerView.setItemAnimator(new DefaultItemAnimator());
              recyclerView.addItemDecoration(new SimpleDivider(getActivity().getApplicationContext()));
  
              final ObjectAdapter objectAdapter = new ObjectAdapter(objects, R.layout.card_object);
              objectAdapter.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      // Here I can manage my Object attributes,
                      // but no the ImageButtons itselves
                  }
              });
  
              recyclerView.setAdapter(objectAdapter);
          }
      }
  
      private ArrayList&lt;Object&gt; initializeList() {
          ArrayList&lt;Object&gt; objects= new ArrayList&lt;&gt;();    
          objects.add(new Object(...));    
          return objects;
      }
  }
  </code></pre>
  
  <p>I can obtain the values of the <code>Object</code> attributes (name, title, whatever), and click on the <code>CardView</code> and so on, but I'm not able to make that the <code>ImageButton</code>have their own onClick. </p>
  
  <p>I don't know if using <code>android:onClick()</code> it would be possible to display the information of a specific card, but this is another thing.</p>
  
  <p>So my question is how can I make that this two buttons do have their own <code>OnClickListener</code>, where I should declare it and how can handle the information of each item of the <code>RecyclerView</code> after that (this part is almost achieved).</p>
  
  <p>Any idea? Thanks a lot!</p>