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

非 Y 不嫁゛ 提交于 2019-12-18 09:37:48

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/28772290/how-to-add-string-in-int-r-string-nameinteger-parsemyindex-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!