I got in trouble to use dataBinding with google codelab.
It happened when I tried using below function.
    @BindingAdapter("app:hideIfZero")
    fun hideIfZero(view: View, number: Int) {
        view.visibility = if (number == 0) View.GONE else View.VISIBLE
    }
I called it in xml like the following code.
    <ProgressBar
        ...
        app:hideIfZero="@{viewmodel.likes}"
        ... />
The viewModel is like the below.
class SimpleViewModel : ViewModel() {
    ...
    private val _likes = MutableLiveData(0)
    ...
    var likes: LiveData<Int> = _likes
I already tried to remove all cache Android Studio produced 
but it didn't work what I intend.
So I think there is a problem I missed.
I tried thie codelab https://codelabs.developers.google.com/codelabs/android-databinding/#7 
and my repository is here https://github.com/libliboom/codelab-data-binding
Anyone who let me know the problem?
Finally, I solved the issue I reported owing to the following link.
https://github.com/googlecodelabs/android-databinding/issues/11
You should add 'kotlin-kapt' that is annotation processor.
It was hard to figure out the issue clear.
I also updated my repository related to this issue in below link.
https://github.com/libliboom/codelab-data-binding/commit/a98e3dc6079f542a49698a4d717b71ad4737dfdf
I hope it helps someone who is struggling with this someday.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With