ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-11 02:25:27  阅读:300  来源: 互联网

标签:android radio-button android-databinding two-way 2-way-object-databinding


我试图以两种方式绑定我的模型的布尔值到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:

<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,radio-button,android-databinding,two-way,2-way-object-databinding
来源: https://codeday.me/bug/20190711/1429501.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有