is this possible to send parameters to binding events from xml views
When you add an id to a view, this view is accessible by this id from the binding. This includes accessing it from within bindings set in the layout itself.
<EditText
android:id="@+id/login_edt_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
<EditText
android:id="@+id/login_edt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_edt_user_name"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/login_btn_sign_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="@{() -> login.onLogin(loginEdtUserName.getText(), loginEdtPassword.getText())}"
android:layout_below="@+id/login_edt_password"
android:text="SIGN IN" />
This can be solved using 2-way Databinding (available since version 2.1 of the Gradle Plugin).
Alternative 1:
Import android.view.View
in your XML:
<data ...>
<import type="android.view.View"/>
</data>
Then, you will be able to reference some attributes of your Views directly in XML. In Lambda Expressions, like you're using, you can also use the Views like you would in Java. Concretely:
android:onClick="@{() -> login.onLogin(login_edt_username.getText().toString(), login_edt_password.getText().toString())}"
Alternative 2: Using a POJO. Given a POJO modelling your credential information, such as
public class Credentials {
public String username;
public String password;
}
, after declaring this model in your XML
<data>
<variable
name="login"
type="interfaces.login.LoginInterface" />
<variable
name="credentials"
type="models.login.Credentials" />
</data>
You could do:
<!-- .... -->
<EditText
android:id="@+id/login_edt_user_name"
android:layout_width="match_parent"
<!-- This binds the value of the Edittext to the Model. Note the equals sign! -->
android:text="@={credentials.username}" />
<EditText
android:id="@+id/login_edt_password"
<!-- Same here -->
android:text="@={credentials.password}" />
<!-- ... -->
and finally, to fit your requirement
android:onClick="@{() -> login.onLogin(credentials.username, credentials.password)}"