Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches

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?

like image 413
libliboom Avatar asked Dec 04 '19 02:12

libliboom


1 Answers

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!

like image 70
libliboom Avatar answered Sep 25 '22 12:09

libliboom