title: Android: OnClick listener on a button in a listview populated with an adapter
body: <p>So I have a <code>ListView</code> that is populated from an <code>ArrayList&lt;&gt;</code> of an object via a custom adapter. </p>
  
  <p>Each row in the <code>ListView</code> is a horizontal layout that contains a <code>TextView</code> widget and a Button widget. There can be between <code>0</code> and <code>2</code> rows in this <code>ListView</code>.</p>
  
  <p>I want to be able to have an <code>onClick</code> method on the <code>Button</code> which allows me to pass to the method in the <code>onClick</code> the position of the <code>Button</code> clicked in the list (i.e. was it in the 1st or 2nd row?) </p>
  
  <p>This is the <code>XML</code> of the page with the <code>ListView</code> (the button listed here is irrelevant for this question)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:orientation="vertical"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  &gt;
  
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingBottom="20dp"
      android:text="Saved Offer Leaflets"
      android:textStyle="bold"
      android:textSize="30dp"/&gt;
  
  &lt;ListView
      android:id="@+id/listViewPdfs"
      android:layout_width="match_parent"
      android:layout_height="100dp" /&gt;
  
  &lt;Button
      android:layout_height="100dp"
      android:layout_width="match_parent"
      android:text="Check for latest offers"
      android:textSize="20dp"
      android:id="@+id/buttonCheckLatestOffers"
      /&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is my list item for the adapter</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  &lt;LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal"&gt;
  &lt;TextView
      android:id="@+id/date"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingBottom="20dp"
      android:textSize="20dp"
      android:text="date" /&gt;
  
  &lt;Button
      android:layout_height="match_parent"
      android:id="@+id/buttonOpenPdf"
      android:layout_width="wrap_content"
      android:text="Open"
       /&gt;
    &lt;/LinearLayout&gt;
    &lt;/LinearLayout&gt;
  </code></pre>