我试图以两种方式将我的模型的布尔值绑定到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));
}
}
};
值得一提的是,当我删除&#34; =&#34;标志,代码编译。
请帮帮我......
答案 0 :(得分:0)
好的,我通过将我的类的名称从ReceiveDataContainer更改为ReceiveContainer来解决它。我不知道为什么会有效,但它确实......
此处有更多信息:https://code.google.com/p/android/issues/detail?id=212492