我试图以两种方式将我的模型的布尔值绑定到 RadioButton。但是,代码无法编译。我有以下错误消息:
错误:(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));
}
}
};
值得一提的是,当我删除“=”符号时,代码会编译。
请帮我...