0

I'm using Android Data Binding library with Android Studio (2.2.3) and it's awesome! But, as mentioned by Android developers portal https://developer.android.com/topic/libraries/data-binding/index.html and even Android Studio Lint shows a tip to use special syntax for binding listeners in layout files:

android:onClick="@{aViewModel::aClickCallback}"

but Android Studio marks this one as erroneous at once:

enter image description here

Projects are built without problems, but I wonder if there is a way to fix it.

atlascoder
  • 2,746
  • 3
  • 26
  • 34
  • 1
    Possible duplicate of [Binding expression results in error, but compiles/runs fine](http://stackoverflow.com/questions/42187405/binding-expression-results-in-error-but-compiles-runs-fine) – yennsarah Feb 23 '17 at 06:36

1 Answers1

0

I have same issue, but I have not found solution except using listener binding instead of method reference. In your case it's looks like:

android:onClick="@{(view) -> aViewModel.aClickCallback(view)}"

Take note:

The major difference between Method References and Listener Bindings is that the actual listener implementation is created when the data is bound, not when the event is triggered. If you prefer to evaluate the expression when the event happens, you should use listener binding.

Sergei Bubenshchikov
  • 5,275
  • 3
  • 33
  • 60