4

I am trying to bind in two ways boolean value of my model to RadioButton. However, the code doesn't compile. I have following error messages:

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

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

And there is generated code marked as invalid:

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

What's worth mentioning is that when i remove "=" sign, code compiles.

Please help me...

Smittey
  • 2,475
  • 10
  • 28
  • 35

1 Answers1

0

Okay, I solved it by changing name of my class from ReceiveDataContainer to ReceiveContainer. I have no idea why that works but it does...

More info here: https://code.google.com/p/android/issues/detail?id=212492

  • It depends on the length of the variable name in your layout. I had some long names and encountered this bug. Shortening the names works. It also looks like it was fixed in AS 2.3 – Cameron Ketcham Dec 08 '16 at 18:52