1

How to add string in int?

R.string.name+Integer.parse(myindex). 

not working.Link txtt.setText(getString(R.string.("i" + j++))); not helpful. others found

Community
  • 1
  • 1
frodopusto
  • 37
  • 6

2 Answers2

2

you can use getIdentifier() to retrieve the string's id, it returns a resource identifier for the given resource name.

 int stringId = getResources().getIdentifier("name"+myIndex, "string", getPackageName());
 if (stringId > 0) {
   textView.setText(stringId);
 }

if you are looking for a String array, the syntax is slightly different:

int stringId = getResources().getIdentifier("name"+myIndex, "array", getPackageName());
String[] array = getResources().getStringArray( stringId ); 
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • `int stringId = getResources().getIdentifier("name"+indexAuthor, "string", getPackageName()); masText = getResources().getStringArray( stringId );` String array resource ID #0x0 – frodopusto Feb 27 '15 at 19:04
  • no wait, are you looking for a string id or a string array id? – Blackbelt Feb 27 '15 at 19:06
  • you are mistaken. The id of a string-array is contained in a different class. Check my update – Blackbelt Feb 27 '15 at 19:09
0
R.string.name+String.valueOf(myindex);
scubasteve623
  • 637
  • 4
  • 7