0
我有一個Android的數據綁定XML:在onClick時獲取其他視圖的值。數據綁定
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="presenter" type="com.myapp.presentation.presenter.CreateUserPresenter"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/firstNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:hint="@string/first_name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/secondNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:hint="@string/second_name" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btnCreate"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text="@string/create"
android:onClick="@{(view) -> presenter.createUser()}" />
</LinearLayout>
</layout>
和CreateUserPresenter.class
:
public class CreateUserPresenter {
public CreateUserPresenter() {}
public void createUser(String firstName, String lastName) {
}
}
如何通過輸入(firstNameInput
和secondNameInput
)值在點擊按鈕的方法createUser()
?
android:onClick="@{(view) -> presenter.createUser()}"
檢查這裏http://stackoverflow.com/a/37105213/1790537 – Nas