txtt.setText(getString(R.string.("i" + j++)));

txtt.setText(getString(R.string.("i" + j++)));

这段代码有什么问题?我想自动使用 id 。我认为在 R.string 之后有一个错误。我能做什么

// initialization for TextView
TextView txtt = (TextView) findViewById(R.id.myTextViewId);
// set the text
txtt.setText(getResources().getString(R.string.mystring));

这样做

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

像这样设置你的值

int stringVal = getStringIDFromName("i" + j++);
if( stringVal != 0)
    txtt.setText(getResource().getString(stringVal));

只有当您做对了所有其他事情时,这才会起作用。