title: ListView row buttons: How do I create a custom Adapter that connects a View.OnClickListener to a button on each row of a ListView?
body: <p>I want my ListView to contain buttons, but setting the button's xml property, onClick="myFunction" and then placing a public void myFunction(android.view.View view) method in the activity causes an NoSuchMethodException (the stack trace is null) to be thrown, as although the onclick listener is there, it doesn't fire myFunction(...) and cause the activity to close.</p>
  
  <p>How do I create a custom Adapter that connects a View.OnClickListener to a button on each row of a ListView?</p>
  
  <p>My ListView is created as follows...</p>
  
  <p>[activity.java content..]</p>
  
  <pre><code>public void myFunction(android.view.View view)
  {
      //Do stuff
  }
  </code></pre>
  
  <p>[activity.xml content..]</p>
  
  <pre><code>&lt;LinearLayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".FrmCustomerDetails" &gt;
      &lt;ListView android:id="@+id/LstCustomerDetailsList" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:clickable="true" android:clipChildren="true" android:divider="@null" android:dividerHeight="0dp" android:fastScrollEnabled="true" android:footerDividersEnabled="false" android:headerDividersEnabled="false" android:requiresFadingEdge="vertical" android:smoothScrollbar="true" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>[activity_row_item.xml content..]</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/Llt" android:layout_width="match_parent" android:layout_height="match_parent" &gt;
      &lt;Button android:id="@+id/Btn" android:text="Click me" android:onClick="myFunction" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>