txtt.setText(的getString(R.string(QUOT。I&QUOT + J ++))); [英] txtt.setText(getString(R.string.("i" + j++)));
本文介绍了txtt.setText(的getString(R.string(QUOT。I&QUOT + J ++)));的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么不对的code?我想自动使用ID。我认为R.string后有一个错误。我能做些什么
What's wrong with this code? I want to use id automatically. I think after R.string there is a mistake. What can ı do
推荐答案
做这样
public static int getStringIDFromName(String stringName)
{
int stringID= 0;
if(stringName == null
|| stringName.equalsIgnoreCase(""))
{
return 0;
}
try
{
@SuppressWarnings("rawtypes")
Class res = R.string.class;
Field field = res.getField(stringName);
stringID = field.getInt(null);
}
catch(Exception e)
{
// Error
}
return stringID;
}
设置你的价值是这样
Set your value like this
int stringVal = getStringIDFromName("i" + j++);
if( stringVal != 0)
txtt.setText(getResource().getString(stringVal));
如果你正在做的一切好的,这只会工作。
This would work only if you are doing everything else right.
这篇关于txtt.setText(的getString(R.string(QUOT。I&QUOT + J ++)));的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文