-1

i am a newbie here. My question is as below:

This is my value/strings.xml file:

<string name="bm">Mengawal</string>
<string name="bi">Managing</string>
 <string name="penan">Penan</string>
<string-array name="menu">
    <item>@string/bm</item>
    <item>@string/bi</item>
    <item>@string/penan</item> 
</string-array>

I have my dynamically assign button in my java file. Now, i want to set the button id programmatically from the xml above. For example,

the button text is ="Mengawal" I wana set the button id to become ="bm"

I saw an example over here, but i cant understand what it actually means. Or is it possible for me to make it like this? Is it possible to access a string-array item in Android?

Thanks for the help.

Community
  • 1
  • 1
Yuen Tong
  • 789
  • 3
  • 9
  • 11

1 Answers1

0

You cannot dynamically set resource ids. Those are compiled into your apk when you build your app.

There is a sort-of workaround described here, where you read in a layout, modify it, save it to the SD card, create an AssetManager for it then you can use it... but it's still not modifying a resource id for an existing resource.

Community
  • 1
  • 1
Barak
  • 16,318
  • 9
  • 52
  • 84