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
  • 2
  • 11

1 Answers1

6

Use:

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

and:

findViewById<TextView>(R.id.textView).text = getString(R.string.some_string, amount)
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491