samedi 21 février 2015

Concatenating an Android's string resource with a hard-coded string

I am working in an Android project in which I created a string resource in the values/strings.xml file. Let's say this is the string:



<string name="some_text">HELLO WORLD</string>


I can call this string from anywhere inside my project like so:



Toast.makeText(MyActivity.this,
R.string.some_text,
Toast.LENGTH_SHORT).show();


This generates a Toast with the text "HELLO WORLD" in it.


But if I try to concatenate this string with some hard-coded text like this:



Toast.makeText(MyActivity.this,
R.string.some_text + String.valueOf(123),
Toast.LENGTH_SHORT).show();


I get this nasty result:


"2131368234234 123"


instead of:


"HELLO WORLD 123".


Does someone know what is happening here?


Thanks


Aucun commentaire:

Enregistrer un commentaire