title: Pass Callback Function to Custom View in Android
body: <p>I have a custom view in my android project, <code>MyCustomView</code>.</p>
  <p>With a built-in view like button, I can use the data binding library to pass a callback function to the button:</p>
  <pre class="lang-xml prettyprint-override"><code>
  &lt;Button
      ...
      android:onClick=&quot;@{() -&gt; viewModel.donePressed()}&quot; /&gt;
  
  </code></pre>
  <p>How can I pass a callback function which I can access in the <code>MyCustomView</code> class through the XML?</p>
  <p>I want it to look something like this:</p>
  <pre class="lang-xml prettyprint-override"><code>
  &lt;MyCustomView app:onFinish=&quot;@{() -&gt; viewModel.finish()}&quot; /&gt;
  
  </code></pre>
  <p>Then in the <code>MyCustomView</code> class (extending <code>LinearLayout</code>) I need to call the <code>onFinish</code> variable.</p>
  <p>Thank you for any ideas.</p>