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

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -