Answer the question
In order to leave comments, you need to log in
Why is the handler method not called when the button is clicked (Data Binding)?
I am using Data Binding. In the EventHandlers class, I implemented a click handler, but when I click on the button, this handler is not called.
<data>
<variable
name="model"
type="com.codit.planit.viewmodel.RegisterViewModel" />
<variable
name="handler"
type="com.codit.planit.handler.EventHandlers" />
</data>
<Button
android:id="@+id/sign_up_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/confirm_pass_input"
android:layout_centerHorizontal="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/sign_up"
android:onClick="@{() -> handler.onSignUpClick(model)}"
style="@style/buttonStyle"/>
public class EventHandlers {
public void onSignInClick(LoginViewModel model){
model.signIn();
}
public void onSignUpClick(RegisterViewModel model) {
model.signUpWithEmailAndPassword();
}
}
ActivityRegisterBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_register);
binding.setModel(ViewModelProviders.of(this).get(RegisterViewModel.class));
binding.setHandler(new EventHandlers());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question