0

I know that its possible to insert local variables into hardcoded strings, like

val amount = "10"
findViewById<TextView>(R.id.textView).text = "There are $amount things."

would output There are 10 things.. However, when I try to do the same thing in the strings.xml file, like

<resources>
<string name="some_string">There are $amount things.</string>
</resources>
val amount = "10"
findViewById<TextView>(R.id.textView).text = getString(R.string.some_string)

the output is There are $amount things.. How can I solve this problem?

ChocolateChapta
  • 148
  • 1
  • 9

1 Answers1

2

Use:

<string name="some_string">There are %s things.</string>

and:

findViewById<TextView>(R.id.textView).text = getString(R.string.some_string, amount)
CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367