モデルのブール値を RadioButton に 2 つの方法でバインドしようとしています。ただし、コードはコンパイルされません。次のエラー メッセージがあります。
エラー:(41, 21) エラー: 変数 receiveDataContainer はメソッド onChange() で既に定義されています
エラー:(45, 59) エラー: 互換性のない型: ブール値を ReceiveDataContainer に変換できません
エラー:(46, 17) エラー: 互換性のない型: ReceiveDataContainer をブール値に変換できません
私のクラス:
public class ReceiveDataContainer extends BaseObservable {
private boolean isShopReceiveMethodChosen;
@Bindable
public boolean isShopReceiveMethodChosen() {
return isShopReceiveMethodChosen;
}
public void setShopReceiveMethodChosen(boolean isShopReceiveMethodChosen) {
this.isShopReceiveMethodChosen = isShopReceiveMethodChosen;
notifyPropertyChanged(BR.shopReceiveMethodChosen);
}
}
XML:
<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/inputLayoutPhoneNumber">
<RadioButton
android:id="@+id/radio_receive_in_store"
android:text="@string/radio_button_receive_in_store"
android:checked="@={receiveDataContainer.shopReceiveMethodChosen}"
style="@style/CartReceptionRadioButton" />
<RadioButton
android:id="@+id/radio_send_to_home"
android:text="@string/radio_button_send_to_home"
style="@style/CartReceptionRadioButton" />
</RadioGroup>
そして、無効としてマークされたコードが生成されます。
// Inverse Binding Event Handlers
private android.databinding.InverseBindingListener radioReceiveInStorea = new android.databinding.InverseBindingListener() {
@Override
public void onChange() {
// Inverse of receiveDataContainer.shopReceiveMethodChosen
// is receiveDataContainer.setShopReceiveMethodChosen((boolean) callbackArg_0)
boolean callbackArg_0 = radioReceiveInStore.isChecked();
// localize variables for thread safety
// receiveDataContainer.shopReceiveMethodChosen
boolean shopReceiveMethodCho = false;
// receiveDataContainer
com.abastra.home_cook.catalogue.data.models.ReceiveDataContainer receiveDataContainer = mReceiveDataContaine;
// receiveDataContainer != null
boolean receiveDataContainer = false;
receiveDataContainer = (receiveDataContainer) != (null);
if (receiveDataContainer) {
receiveDataContainer.setShopReceiveMethodChosen((boolean) (callbackArg_0));
}
}
};
言及する価値があるのは、「=」記号を削除すると、コードがコンパイルされることです。
私を助けてください...