android - Is there a way to do this...R.Id."string"? -


i have folder called "raw" in res folder selection of short audio tracks , screen displays several buttons.

i able start mediaplayer this...

string[] track = {"track1", "track2", "track3", etc...}  mplayer = mediaplayer.create(this, r.raw.track[x]); 

the issue r.raw.track[x].

is there way in way i'm attempting or need whole new approach?

thanks in advance advice can offer.

i going assume here x index, perhaps pulled user selection track.

you have 2 main options:

  1. have corresponding int[] {r.raw.track1, r.raw.track2, ...} , r.raw value way

  2. use getresources().getidentifier() identifier @ runtime

the second option easier uses reflection , not super-quick. in case, should not matter, doubt looking these ids in tight loop.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -