I am trying to pass views using Listener binding in onFocusChange function but get the following error
The callback android.view.View.OnFocusChangeListener#onFocusChange has 2 methods but the lambda defined has 1. It should have either 0 or equal number of parameters.
Please can somebody help me in finding the right way to implement this.
    <variable
        name="user"
        type="com.webage.www.vco_address.User" />
    <variable
        name="obj"
        type="com.webage.www.colin.Validations" />
</data>
    <EditText
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="82dp"
        android:text="@={user.name}"
        android:onFocusChange="@{(view)->obj.saveClick(view, user.name)}" />
Validations
public class Validations {
    public void saveClick(View view, String name){
        Log.v("saveClick",name);
    }
}
                I believe that the error message is worded incorrectly. It doesn't make any sense that onFocusChange() has two methods since it is a method. More likely, the problem is that onFocusChange() has two parameters, a View and a boolean. You have declared the lambda to take only one parameter. Just add a second parameter to the lambda.
for xml:
app:onFocusChangeListener = "@{viewModel::onTargetFocusChanged}"
for program code:
fun onTargetFocusChanged(view: View, hasFocus: Boolean){
        ...
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With