开发者

how to add items name in alert dialog from strings.xml in android

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.Buil开发者_高级运维der(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...


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜