android绑定单选按钮,带单选按钮的Android双向数据绑定

我试图以两种方式绑定我的模型的布尔值到RadioButton.

但是,代码无法编译.我有以下错误消息:

Error:(41,21) error: variable receiveDataContainer is already defined

in method onChange()

Error:(45,59) error: incompatible types: boolean cannot be converted

to ReceiveDataContainer

Error:(46,17) error: incompatible types: ReceiveDataContainer cannot

be converted to boolean

我的课:

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:

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

android:id="@+id/radio_receive_in_store"

android:text="@string/radio_button_receive_in_store"

android:checked="@={receiveDataContainer.shopReceiveMethodChosen}"

style="@style/CartReceptionRadioButton" />

android:id="@+id/radio_send_to_home"

android:text="@string/radio_button_send_to_home"

style="@style/CartReceptionRadioButton" />

并且生成的代码标记为无效:

// 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));

}

}

};

值得一提的是,当我删除“=”符号时,代码会编译.

请帮我…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值