Ad

How Can Concat Two Integers In A TextView Using Databinding?

I have a ViewModel with the next variables:

public MutableLiveData<Integer> questionPosition = new MutableLiveData<>();
public MutableLiveData<Integer> totalQuestions = new MutableLiveData<>();

And I want show it in a TextView like questionPosition/totalQuestions (this is not a division)

android:text='@={examViewModel.questionPosition + "/" + examViewModel.totalQuestions}'

But in the two cases fail.

How can do it?

Thanks

EDIT

The problem was that I had not to initialize the ViewModel in the Activity, but the code of the question work too.

Ad

Answer

try this:

in String.xml

<string name="output"> %1$s / %2$s </string>

in you xml file

android:text="@{@string/output(examViewModel.questionPosition, examViewModel.totalQuestions)}"
Ad
source: stackoverflow.com
Ad