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

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -