title: Android: Add event listeners to every item in a ListView
body: <p>I have an Android app with a ListView, and each row in the list has a TextView and a Button. What I want to do is add an OnClickListener to each Button in the ListView, but I can't figure out how to get some sort of reference to every Button... Can anyone please give me a hint?</p>
  
  <p>Here's my XML that's bound to the ListAdapter:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"&gt;
  &lt;TextView 
      android:id="@+id/row_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:textSize="18sp"&gt;
  &lt;/TextView&gt;
  &lt;Button
      android:id="@+id/row_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And I tried something like this, but it doesn't work:</p>
  
  <pre><code>SimpleCursorAdapter rows = new SimpleCursorAdapter(this, R.layout.row_layout, cursor, from, to);
  setListAdapter(rows);
  Button button = (Button) getListAdapter().getView(0, null, getListAdapter()).findViewById(R.id.row_button);
  button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
          Log.i(TAG, "clicked");
      }
  }); 
  </code></pre>