Issue
in my app I do a web request that returns some result code, e.g. 105. I have string resources that look like that
<string name="r105">O.K.</string>
<string name="r106">Something went wrong.</string>
<string name="r333">Fatal error.</string>
Now I want to do something like that
Toast.makeText(parent.getApplicationContext(),
parent.getString(R.string.r+resultCode), Toast.LENGTH_LONG).show();
while r+resultCode
is the resource identifier.
This does not work. Any idea how to do that?
Solution
Try this getResources().getIdentifier(name, defType, defPackage)
in a simple way.
Toast.makeText(this, getResources().getIdentifier("r"+resultcode, "string",
getPackageName()), Toast.LENGTH_LONG).show();
Answered By - Lalit Poptani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.