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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -