Search code examples
androidxmlandroid-databinding

Passing a string value via xml to viemodel (Databinding)


I wonder what's the proper syntax of passing value to viewmodel. I use this expression

android:onClick="@{() -> viewModel.rightColor("I WANT TO PUT RAW STRING HERE")}"

Is there any way to put raw string (like "DOG") to this expression?

Before you ask, databinding works in my projekt (just don't know how to deal this problem), I also have viewModel variable in XML.

Thanks in advance


Solution

  • I managed to round the problem. The way to do that is to extract string resource and put it in this way:

    android:onClick="@{() -> viewModel.rightColor(@string/extracted_string)}"
    

    Hope it will help somebody