Search code examples
javaandroidsettext

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


Solution

  • 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);