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?

0

1 Answer 1

6

Use:

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

and:

findViewById<TextView>(R.id.textView).text = getString(R.string.some_string, amount)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.