Set Android app Lanuage programatically

Source: Internet
Author: User

问题:

I am developing a comic app. I have three radio buttons which is english,french and Spanish respectively. And when the user clicks on any one of them the strings.xml from VALUES-ES,VALUES-FR and values-en should change the Strin G of the required references but and I-click on the radio buttons it does the references is still in Engish an D do not change to French or Spanish



Answer:
public class Androidlocalize extends Activity {Spinner Spinnerctrl; Button btn; Locale Mylocale; @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Spinnerctrl = (Spinner) Findviewbyid (r.id.spinner1); Spinnerctrl.setonitemselectedlistener (New Onitemselectedlistener () {public void onitemselected (Adapterview<?>Parent, ViewView, IntPos, LongId) { If (Pos== 1) { Toast.Maketext(Parent.GetContext(), "You have selected Es", Toast.Length_short) .Show();SetLocale("Ta"); } Else If (Pos== 2) { Toast.Maketext(Parent.GetContext(), "You have selected Fr", Toast.Length_short) .Show();SetLocale("Hi"); } Else If (Pos== 3) { Toast.Maketext(Parent.GetContext(), "You have selected En", Toast.Length_short) show (); Setlocale ( } } public void Onnothingselected ( adapterview<?> arg0) {//TODO auto-generated method stub } }); public void SetLocale (String lang) {Mylocale = new Locale (lang); Resources res = getresources (); Displaymetrics DM = Res.getdisplaymetrics (); Configuration conf = res.getconfiguration (); Conf.locale = Mylocale; Res.updateconfiguration (conf, DM); Intent refresh = new Intent (this, androidlocalize.class); StartActivity (refresh); }}


turn from: Stack overflow

Set Android app Lanuage programatically

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.