I am implementing onstartIconClickletener using a custom attribute and Binder method
My Layout element is
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text.layout.email.and.phone"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:hint="@string/txt_email_phone"
android:textColorHint="@color/bg_input_text"
app:boxStrokeColor="@color/bg_input_text"
app:hintTextColor="@color/bg_input_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:prefixTextColor="@color/text_color_white_1"
app:startIconDrawable="@drawable/ic_down_arrow"
app:startIconTint="@color/colorPrimaryDark"
app:onStartIconClicked = "@{(view)->viewModel.onStartIconClicked(view)}"
app:prefixText="@{viewModel.prefixText}">
I created an interface with one single method
public interface StartInconOnClickListener {
void onStartIconClicked(View view);
}
In my BindingAdapter
@BindingAdapter({"app:onStartIconClicked"})
public static void setonStartIconClickedListener(TextInputLayout textInputLayout, StartInconOnClickListener newListener) {
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override public void onClick(View v) {
newListener.onStartIconClicked(v);
}
};
textInputLayout.setStartIconOnClickListener(onClickListener);
}
But clicking the startIcon it is invoking onClick in the BindingAdapter, but it is not calling my lambda function in the ViewModel
My Lamda function in the view model is
public void onStartIconClicked(View view) {
prefixText.set("+91");
Event event = new Event(Boolean.valueOf(true));
_showCountryCodeDialog.setValue(event);
}
I spent the whole day. now I am looking for help