I'm working on this project https://developer.android.google.cn/codelabs/basic-android-kotlin-training-project-lunch-tray , and the final project is very similar to https://github.com/ErickPimentel/LunchTray , but I add android:checked
to RadioButton
, for example, @{viewModel.accompaniment.name.equals(@string/bread)}
(I put all hard coded strings in string.xml
).
But it does not work fine, it can't checked any radio button.
CodePudding user response:
I check your AccompanimentMenuFragment android:checked="@{viewModel.accompaniment.name.equals(@string/pickles)}"
Here viewModel.accompaniment.name has value "Pickled Veggies" and in string "pickles".
viewModel.setAccompaniment(@string/pickles)}" is setting value from your DataSource which has name "Pickled Veggies".
_accompaniment.value = menuItems[accompaniment] in this line menuItems[accompaniment] is getting value from DataSource which has
"pickles" to MenuItem( name = "Pickled Veggies", description = "Pickled cucumbers and carrots, made in house", price = 0.50, type = ItemType.ACCOMPANIMENT )
Hence you "Pickled Veggies" is getting compared with "pickles" which gives false result. Same issue is with other fragments