Darksymphony
Darksymphony

Reputation: 2683

setText() multiple strings from xml

Maybe a simple question - I need help to setText multiple strings from my strings.xml.

 mytext.setText(resources.getString(R.string.history_text1+R.string.history_text2));

So I mean I need to put 2 different text as one via one setText.

However with this syntax I have an error: android.content.res.Resources$NotFoundException: String resource ID #0xfe1e0079

Upvotes: 0

Views: 926

Answers (2)

forpas
forpas

Reputation: 164069

The values:
R.string.history_text1 and R.string.history_text2
are integer numbers referencing the actual strings in resources.
By adding them you get another integer that references nothing, so you get:

Resources$NotFoundException

If you want to concatenate the 2 string values:

String value = resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2)
mytext.setText(value);

Upvotes: 1

Ekrem
Ekrem

Reputation: 405

Try this:

 mytext.setText(resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2))

Upvotes: 2

Related Questions