Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@BindingAdapter getSelectedItemPosition(android.widget.Spinner) has 1 attributes and 0 value parameters. There should be 1 or 2 value parameters

Tags:

android

I am implementing 2 way databinding involving a Spinner. I am getting the following error. Any help appreciated.

Error:(105, 16) error: @BindingAdapter getSelectedItemPosition(android.widget.Spinner) has 1 attributes and 0 value parameters. There should be 1 or 2 value parameters.

Here is my code

Model code

@BindingAdapter({"bind:selection"})
public int getSelection(Spinner view) {
    return view.getSelectedItemPosition();
}

@BindingAdapter({"bind:selection"})
public void setSelection(Spinner view, int position) {
    view.setSelection(position);
    notifyPropertyChanged(BR.position);
}

XML Code

<?xml version="1.0" encoding="utf-8"?>
<layout>
    <data>
        <variable
            name="payment"
            type="com.ananth.finance.model.MakePayment" />
    </data>

    <RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">



                    <Spinner
                        android:id="@+id/paymentName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp"
                        android:entries="@{payment.allPayments}"
                        android:selection="@={payment.selectedItemPosition}"
                        android:padding="7dp" />

            </RelativeLayout>
        </ScrollView>
    </RelativeLayout>
</layout>
like image 255
Ananth Avatar asked Oct 21 '25 08:10

Ananth


1 Answers

The method which is annotated with @BindingAdapter needs to have atleast two parameters . Since this error will not let you build your app . Try this once

@BindingAdapter({"bind:selection"}) 
public int getSelection(Spinner view,MakePayment model) {
 return view.getSelectedItemPosition();
} 

Try to run your application once with once . In case of issue let me know

like image 61
Salil Kaul Avatar answered Oct 23 '25 21:10

Salil Kaul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!