android - How to get resource id from String in Andriod -


i need resource id string

string s = "r.raw.button5";  final mediaplayer mp2 = mediaplayer.create(this,integer.valueof((s)); 

you can use getidentifier(....). if have button id "r.id.button5" code.

int id = getresources().getidentifier("button5", "id", context.getpackagename()); final mediaplayer mp2 = mediaplayer.create(this,id); 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -