1

in my app when i click a button i am opening an Alert Dialog builder. My code is as follows

AlertDialog.Builder builder = new AlertDialog.Builder(BannerImage.this);
final CharSequence[] items = {"Skip", "video", "Audio", "Games"};
builder.setTitle(" Funn ");

here instead of typing the items name here i want to add those name from R.strings.xml file but it shows some errors, as my user changes the locale i want to show different language for that i need to do like this. How to add the values from strings file...

Siva K
  • 4,968
  • 14
  • 82
  • 161

2 Answers2

4
final CharSequence[] items = {getString(R.string.skip), getString(R.string.video), getString(R.string.audio), getString(R.string.games)};

and then create your string.xml file

<resources>
<string name="skip">skip</string>
<string name="video">Video</string>
<string name="audio">Audio</string>
<string name="games">Games</string>
</resources>


<resources>
<string name="skip">Siguiente</string>
<string name="video">Video</string>
<string name="audio">Audio</string>
<string name="games">Juegos</string>
</resources>
vsm
  • 3,373
  • 2
  • 25
  • 36
0

You neeed to create seperate resource files for each language. E.G

  1. res/values/strings.xml - For all English strings that the application uses.
  2. res/values-fr/strings.xml - For all French strings that the application uses.
  3. res/values-ja/strings.xml - For all Japanese strings that the application uses.

Please read the Localization article for more info.

Ravi Vyas
  • 12,212
  • 6
  • 31
  • 47