Wednesday, 28 August 2013

Can't get string resource from R.string.*

Can't get string resource from R.string.*

I have SQlite table with two column _id and name. For internationalization
purpose I store the name like R.string.today Now I want to get string
resource associated with R.string.today:
String column = myCursor.getString(myCursor.getColumnIndex(MainDb.NAME));
int resId = getApplicationContext().getResources().getIdentifier(column,
"strings", getApplicationContext().getPackageName());
String buttonText;
if (resId != 0)
{
buttonText = getApplicationContext().getString(resId);
} else
{
buttonText = "Resource is null!";
}
resId is always 0. Variable "column" have the right value, I've checked it
with debugger. I've tried different variations in resId: 1) "string"
instead of "strings" in defType. 2) Different variation of getResources
like Resources.getSystem()... 3) Different variation of getPackageName()
What I'm doing wrong?

No comments:

Post a Comment