java - Using a variable in getString() -


i'm using random number pull string resource xml, of have similar beginning (they named "quote" number after, quote1, quote2, etc.

i'm trying find way access them using getresources().getstring() don't know how pass that, since getstring wants int, can't

string quotetoget="r.string.quote"+string.valueof(randnum)  //randnum random int generated 

because quotetoget string, getstring(quotetoget) doesn't work.

what else achieve this?

with method, should resource name.

private string getresstringid(string astring) {       string packagename = getpackagename();       int resid = getresources().getidentifier(astring, "string", packagename);       return getstring(resid);     } 

use following:

string quotetoget= getresstringid("quote"+string.valueof(randnum)); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -