title: Data bindings with custom listeners on custom view
body: <p>I'm trying to bind an event on a custom view with the new Android data-binding library but run into an issue.</p>
  
  <p>Here's the relevant part of my custom view:</p>
  
  <pre><code>public class SuperCustomView extends FrameLayout {
      private OnToggleListener mToggleListener;
  
      public interface OnToggleListener {
          void onToggle(boolean switchPosition);
      }
  
      public void setOnToggleListener(OnToggleListener listener) {
          mToggleListener = listener;
      }
      .../...
   }
  </code></pre>
  
  <p>I'm trying to use this Custom View and bind the <code>onToggle</code> event with the following:</p>
  
  <pre><code>&lt;data&gt;
      &lt;variable
          name="controller"
          type="com.xxx.BlopController"/&gt;
  &lt;/data&gt;
  
  &lt;com.company.views.SuperCustomView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:onToggle="@{controller.toggleStrokeLimitation}"
         app:custom_title="Blah"
         app:custom_summary="Bloh"
         app:custom_widget="toggle"/&gt;
  </code></pre>
  
  <p>Where <code>toggleStrokeLimitation</code> is a method on the controller:</p>
  
  <pre><code>public void toggleStrokeLimitation(boolean switchPosition) {
      maxStrokeEnabled.set(switchPosition);
  }
  </code></pre>
  
  <p>I get this error when compiling:</p>
  
  <pre><code>&gt; java.lang.RuntimeException: Found data binding errors.
  ****/ data binding error ****msg:Cannot find the setter for attribute 'app:onToggle' with parameter type java.lang.Object. file:/path/to/androidapp/app/src/main/res/layout/fragment_stroke.xml loc:36:35 - 36:67 ****\ data binding error ****
  </code></pre>
  
  <p>I've tried to use <code>android:onToggle</code> instead of <code>app:onToggle</code> but get the same error.</p>
  
  <p>When reading the <a href="https://developer.android.com/tools/data-binding/guide.html#binding_events">binding events section of the doc</a>, I feel like I can wire any method off the controller to the <code>onToggle</code> event.</p>
  
  <p>Does the framework wrap the <code>controller.toggleStrokeLimitation</code> methods into  a <code>SuperCustomView.OnToggleListener</code>? Any hint on the kind of magic that is behind the existing <code>onClick</code> provided by the framework?</p>