gpt4 book ai didi

带有单选按钮的Android双向数据绑定(bind)

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:00 26 4
gpt4 key购买 nike

我正在尝试以两种方式将模型的 bool 值绑定(bind)到 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

我的类(class):

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

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

请帮帮我...

最佳答案

好的,我通过将类名从 ReceiveDataContainer 更改为 ReceiveContainer 解决了这个问题。我不知道为什么会这样,但它确实...

更多信息在这里:https://code.google.com/p/android/issues/detail?id=212492

关于带有单选按钮的Android双向数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40129009/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com