How to change language in android application. I am already using string.xml
file to display a language.
How can I choose between two xml files on clicking on a radio button
How to change language in android application. I am already using string.xml
file to display a language.
How can I choose between two xml files on clicking on a radio button
for this you have to use localization concept.Do Google the Localization in android..... Create a new folder in res folder of your project for each language you want to implement in project. in that folder create a string.xml file
MyProject/
res/
values/<-----------this is default folder
values-fr/ <-----------this folder is for French language(fr is iso code for french language you can check the iso codes for all languages on this link http://www.w3schools.com/tags/ref_language_codes.asp)
similarly create values folder for each language suppose you also have to implement urdu in your project then you will have to create another values folder for urdu likevalues-ur/
now you have three values folders
MyProject/
res/
values <------ default
values-fr <----for french
values-ur <----for urdu
now create a String.xml file in all folders
MyProject/
res/
values/string.xml
values-fr/string.xml
values-ur/string.xml
suppose you have a button and you want to set text of that button according the language you choose... add the contents in all string.xml files like this
"for string.xml in values folder(default folder) this is by default for english"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">create</string>
</resources>
"for string.xml in values-ar" that is for french
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">créer</string>
</resources>
"for string.xml in values-ur" that is for urdu
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">تخلیق</string>
</resources>
now you have created content in string.xml for all three languages. The point to note is that in all string.xml files keep the value for name attribute same
<string name="my_button">Create</string>
here the value for name attribute is "my_button" and its same in all three string.xml. Only you have to change the text between the tags that is create for english créer for french and تخلیق for urdu... now set the text of the button like this
android:text="@string/my_button"
now the question is there are three string.xml files here in your project and from which string.xml the app will set the text of button???? this depends upon the locale of your phone. application will automatically pick text from string.xml according to locale of your phone. suppose the locale of your phone is set to french then app will pick the text from string.xml which is in values-ar folder and text on button will be créer.. if locale is set to urdu app will pick text from string.xml that is for urdu in values-ur folder and text on button will be تخلیق.. you can change the locale of app programatically.. what you have to do with radio buttons ? just change the locale according to the radio button selected..... Hopefully it will help you.