0

I got this variable

val questionType = R.string.add

Here is from the string resource

<string name="add">%d + %d?</string>

I want to pass value to %d by using questionType in a ViewModel, is it possible to do so?

Pson
  • 19
  • 3
  • Does this answer your question? [Is it possible to have placeholders in strings.xml for runtime values?](https://stackoverflow.com/questions/3656371/is-it-possible-to-have-placeholders-in-strings-xml-for-runtime-values) – plplmax Jul 22 '22 at 06:54

1 Answers1

1

Yes it is possible.

<string name="welcome_messages">Hello, You haven't been around %1$s hours.</string>

val text = res.getString(R.string.welcome_messages, hourCount);

someTextview.text = text