title: Android Data Binding - Reference to view
body: <p>I use in my new app the data binding library of android.
  Currently I try to pass a reference of another view to a method.</p>
  
  <p>I have an <code>ImageButton</code> with an <code>onClickListener</code>. In this onClick listener I want to pass a reference of the root view to the method.</p>
  
  <pre><code>&lt;RelativLayout
      android:id="@+id/root_element"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;ImageButton
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentStart="true"
          android:contentDescription="@string/close_dialog"
          android:src="@drawable/ic_close_212121_24dp"
          android:background="@android:color/transparent"
          android:onClick="@{() -&gt; Helper.doSth(root_element)}"/&gt;
  
  &lt;/RelativLayout&gt;
  </code></pre>
  
  <p>This source code provided above is only an example and not the complete.
  There are more children and also the image button is not a direct child of the root element. But I think the meaning is clear.</p>
  
  <p>I already tried to pass a reference by specifying the id of the root view (see above). But this doesn't work. If I try to compile this, I get the error, that the type of <code>root_element</code> is not specified.</p>
  
  <p>I also tried to import the generated binding class and access the root element by the public field in it. Also this method doesn't work, since the binding class has to be generated first.</p>
  
  <p>So is there any way to pass a reference of a view to a method?
  I know that I could pass the id of the root view with <code>@id/root_element</code>, but I don't want that, since I have to find a way to get a reference to this view only with the given id.</p>