Sam Sam - 3 years ago 58
Android Question

Can we get Root View in an xml layout in Databinding?

Something like the following:

android:onClick="@{() -> presenter.onClick(rootView)}"


Source code:

<?xml version="1.0" encoding="utf-8"?>
<layout>

<data>
<variable
name="presenter"
type="Presenter" />
</data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="@{() -> presenter.onClick(rootView)}"
android:text="abcde" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="tytyt" />
</LinearLayout>
</layout>

Answer Source

You can't. But you can create a method in your activity/fragment which returns the view root.Call this method inside the presenter wherever you need it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download