title: Add OnClickListner to CardView and get data
body: <p>I wan to attach an OnClickListener to a CardView, so i can get the ID from the card</p>
  
  <p>I have a RecyclerView that has a custom adapter for displaying the cards. This is how it's implemented.</p>
  
  <p>I tried other examples in stackoverflow but it didn't work .</p>
  
  <pre><code>public class CardAdapter extends RecyclerView.Adapter&lt;CardAdapter.ViewHolder&gt; {
  private ArrayList&lt;Patient&gt; patients;
  Context mContext;
  String idPatient;
  
  public CardAdapter(ArrayList&lt;Patient&gt; patients) {
      this.patients = patients;
      }
  
          @Override
  public CardAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_card_view, viewGroup, false);
      return new ViewHolder(view);
      }
  
  @Override
   public void onBindViewHolder(CardAdapter.ViewHolder viewHolder, int i) {
  
      viewHolder.first_name.setText(patients.get(i).getFirstName());
      viewHolder.last_name.setText(patients.get(i).getLastName());
      viewHolder.id_patient.setText(String.valueOf(patients.get(i).getId()));
  
      viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              //trying to get ID From card
              ViewGroup parentView = (ViewGroup)v.getParent();
              TextView idpatientview =(TextView)parentView.findViewById(R.id.idViewPatient);
              idPatient = idpatientview.getText().toString();
              PreferencesHelper.save(mContext, "idPatient", idPatient);
              Intent intent = new Intent(mContext, BluetoothActivity.class);
               mContext.startActivity(intent);
  
          }
      });
  
      }
  
        @Override
  public int getItemCount() {
      return patients.size();
      }
  
  public class ViewHolder extends RecyclerView.ViewHolder{
              private TextView first_name,last_name,id_patient;
     public ViewHolder(View view) {
          super(view);
  
          first_name = (TextView)view.findViewById(R.id.textViewName);
          last_name = (TextView)view.findViewById(R.id.textViewLastName);
          id_patient = (TextView)view.findViewById(R.id.idViewPatient);
  
     }
          }
                 }
  </code></pre>