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?
Try this getResources().getIdentifier(name, defType, defPackage)
in a simple way.
Toast.makeText(this, getResources().getIdentifier("r"+resultcode, "string",
getPackageName()), Toast.LENGTH_LONG).show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With