如何在int中添加字符串? R.string.name+Integer.parse(我的索引)。不工作

How to add string in int? R.string.name+Integer.parse(myindex). not working

如何在int中添加字符串?

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

不是working.Link 没有帮助。 其他人找到了

R.string.name+String.valueOf(myindex);

您可以使用 getIdentifier() 检索字符串的 ID,它 returns 给定资源名称的资源标识符。

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

如果您要查找字符串数组,则语法略有不同:

int stringId = getResources().getIdentifier("name"+myIndex, "array", getPackageName());
String[] array = getResources().getStringArray( stringId );