2016-07-31 15 views
1

私はSpinnerを含む2ウェイデータバインディングを実装しています。次のエラーが表示されます。どんな助けもありがたい。@BindingAdapter getSelectedItemPosition(android.widget.Spinner)には1つの属性と0の値パラメータがあります。 1つまたは2つの値パラメータがあるはずです

エラー:(105,16)エラー:@BindingAdapter getSelectedItemPosition(android.widget.Spinner)には1つの属性と0の値パラメータがあります。 1つまたは2つの値パラメータが必要です。ここで

は私のコードは

モデルコード

@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コード

<?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> 

答えて

0

少なくとも2つのパラメータを持っている必要があります@BindingAdapterと注釈されている方法です。このエラーはあなたのアプリを構築することはできません。これを一度試してください

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

アプリケーションを1回実行してみてください。問題が発生した場合はお知らせください

関連する問題