I have a settings dialog/activity where I allow the user to change the
locale.  Within that activity i call

                Resources res = ctx.getResources();
                // Change locale settings on the device
                DisplayMetrics dm = res.getDisplayMetrics();
                android.content.res.Configuration conf = res.getConfiguration();
                conf.locale = new Locale(language_code.toLowerCase(),
coutry_code.toUpperCase());
                res.updateConfiguration(conf, dm);

and call onChanged() for my settings ListView...  everything changes
perfectly.  Very nice.

Then I hit the back button to go back to the previous activity
thinking everything should be switched; nope.  Everything is still in
the previous locale.  So I added the above code in the onResume() of
the activity thinking that would do it; nope.  Also, when I click the
menu button of this activity again (not first time) I do not get
called in onCreateOptionsMenu() it just displays the previous menu.

My question is what is the correct way to force existing activities to
reload using the new local?

thanks.
Mark


On Jan 26, 10:39 pm, Raja Nagendra Kumar <nagendra.r...@gmail.com>
wrote:
> Diannel thank you, Deep thank you for the complete source spippet..
>
> On Jan 27, 1:23 am, "deepdr...@googlemail.com"
>
> <deepdr...@googlemail.com> wrote:
> > ya, great, thanks, this works for me ! :
>
> >                 Resources res = getResources();
> >                 DisplayMetrics dm = res.getDisplayMetrics();
> >                 Configuration conf = res.getConfiguration();
> >                 conf.locale = Locale.GERMANY;
> >                 res.updateConfiguration(conf, dm);
> >                 firstline= res.getString(R.string.firstline);
>
> > On Jan 26, 9:09 pm, Dianne Hackborn <hack...@android.com> wrote:
>
> > > You can't just modify the structure, you need to give a new Configuration 
> > > of
> > > new values to Resources.updateConfiguration().
>
> > > On Mon, Jan 26, 2009 at 11:21 AM, deepdr...@googlemail.com <
>
> > > deepdr...@googlemail.com> wrote:
>
> > > > I tried :
>
> > > >                Resources res = getResources();
> > > >                res.getConfiguration().locale = Locale.GERMANY;
> > > >                firstline= res.getString(R.string.firstline);
>
> > > > in my onCreate() . But, although I do have res/values-de/strings.xml
> > > > this still gives me the english string for firstline.
> > > > So it seems to me that there's no easy way to test different languages
> > > > without an actual device for that language (?)
>
> > > > On Jan 24, 10:28 pm, Dianne Hackborn <hack...@android.com> wrote:
> > > > > This isn't really supported, though you can change the language of the
> > > > > Configuration used by your Resources object.  This will only impact 
> > > > > your
> > > > own
> > > > > app, though, not things displayed by others like your notifications
> > > > (those
> > > > > will still use the system's locale).
>
> > > > > On Fri, Jan 23, 2009 at 10:39 PM, Raja Nagendra Kumar <
>
> > > > > nagendra.r...@gmail.com> wrote:
>
> > > > > > Hi Romain,
>
> > > > > > Thank You Romain, a follow up to this how do I change the default
> > > > > > languge to choose in my application based on the menu we provide 
> > > > > > with
> > > > > > in the andorid application..
> > > > > > I may still want to keep my phone locale some thing deferent than 
> > > > > > the
> > > > > > application locale.
>
> > > > > > Regards,
> > > > > > Nagendra
>
> > > > > > On Jan 24, 11:16 am, Romain Guy <romain...@google.com> wrote:
> > > > > > > Hi,
>
> > > > > > > All you need to do is place your resources in locale specific
> > > > > > > directories. For instance:
>
> > > > > > > res\
> > > > > > >   drawable-en\
> > > > > > >   values-fr\
> > > > > > >   layout-jp\
>
> > > > > > > In your example to localize the app in English and German, you 
> > > > > > > would
> > > > > > have:
>
> > > > > > > res\
> > > > > > >   values\
> > > > > > >     strings.xml
> > > > > > >   values-de\
> > > > > > >     strings.xml
>
> > > > > > > And Android will automatically pick up the right strings.xml at
> > > > > > > runtime, depending on the locale. If you want to know more about
> > > > > > > resources and configurations, please readhttp://
> > > > > > code.google.com/android/devel/resources-i18n.html
>
> > > > > > > On Fri, Jan 23, 2009 at 10:10 PM, Raja Nagendra Kumar
>
> > > > > > > <nagendra.r...@gmail.com> wrote:
>
> > > > > > > > Is there any good example to show how a single compiled 
> > > > > > > > application
> > > > > > > > could support both english and say germany..
>
> > > > > > > > The aapt approach and Resource R.java approach seems to me 
> > > > > > > > that, we
> > > > > > > > may need to have one binary for english and one for germany
> > > > etc..and
> > > > > > > > so on..
>
> > > > > > > > Like in J2ME, could we switch the language at runtime..
>
> > > > > > > > Regards,
> > > > > > > > Raja Nagendra Kumar,
> > > > > > > > C.T.O
> > > > > > > >www.tejasoft.com
>
> > > > > > > --
> > > > > > > Romain Guy
> > > > > > > Android framework engineer
> > > > > > > romain...@android.com
>
> > > > > > > Note: please don't send private questions to me, as I don't have 
> > > > > > > time
> > > > > > > to provide private support.  All such questions should be posted 
> > > > > > > on
> > > > > > > public forums, where I and others can see and answer them- Hide
> > > > quoted
> > > > > > text -
>
> > > > > > > - Show quoted text -
>
> > > > > --
> > > > > Dianne Hackborn
> > > > > Android framework engineer
> > > > > hack...@android.com
>
> > > > > Note: please don't send private questions to me, as I don't have time 
> > > > > to
> > > > > provide private support.  All such questions should be posted on 
> > > > > public
> > > > > forums, where I and others can see and answer them.
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > hack...@android.com
>
> > > Note: please don't send private questions to me, as I don't have time to
> > > provide private support.  All such questions should be posted on public
> > > forums, where I and others can see and answer them.- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to