A
A
AndreyRafalsky1322019-06-30 10:45:50
Android
AndreyRafalsky132, 2019-06-30 10:45:50

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"/>

Handler class:
public class EventHandlers {
    public void onSignInClick(LoginViewModel model){
        model.signIn();
    }
    public void onSignUpClick(RegisterViewModel model) {
        model.signUpWithEmailAndPassword();
    }

}

Binding:
ActivityRegisterBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_register);
        binding.setModel(ViewModelProviders.of(this).get(RegisterViewModel.class));
        binding.setHandler(new EventHandlers());

Can you please tell me why the handler.onSignUpClick(model) method is not called? Thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question