Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:05:54+00:00 2026-05-24T10:05:54+00:00

I’ve read many posts about reloading the Activity. I understand it is not the

  • 0

I’ve read many posts about reloading the Activity. I understand it is not the way to go. However, my PreferenceActivity class loads its view via an xml file. In that xml file all names and descriptions reference the the string.xml file. One of these preference options is to change the language. I use an onPreferenceChangeListener definition to catch and set the new Locale right away. I want behaviour similar to the OS where after you change the language its instantly reflected.

To avoid manually defining each preference option, is there not any way at the end of this method that I can force the xml file to be loaded again and thus all the strings to be grabbed from the new locale?

Thanks for your help, here’s what I have so far, I cut out the locale change to save space:

     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);

        Preference langPref = (Preference) findPreference("languagePreference");
        langPref.setOnPreferenceChangeListener( new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {

                /* CHANGE LOCALE */
                ...

                /* FORCE XML TO BE RELOADED */
                HOW?

                return false;
            }
        });
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:05:55+00:00Added an answer on May 24, 2026 at 10:05 am

    I’m not saying this is a good answer but to possibly help others, I’ve been able to make a temporary solution to what I want:

    I’ve put my change listener creation inside a method called setupListener.

    /* FORCE XML TO BE RELOADED */
    
    /* remove existing preferences */
    PreferenceScreen prefScreen = getPreferenceScreen();
    prefScreen.removeAll();
    
    /* add preference screen */
    MyPrefClass.this.addPreferencesFromResource(R.xml.preferences);
    
    /* re-add listener */               
    Preference langPref = (Preference) findPreference("languageLocale");
    MyPrefClass.this.setupListener( langPref );            
    

    The state of the preference isn’t switching properly for me yet but I’m going to live with it for now.

    Updated full code:

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
    
            /* add language listener */
            Preference langPref = (Preference) findPreference("langLocale");
            this.setupListener( langPref );
    
    }
    
    
    protected void setupListener( Preference preference ) {
    
        preference.setOnPreferenceChangeListener( new OnPreferenceChangeListener() {
    
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
    
                /* set master config */
                Locale locale2 = new Locale( newValue.toString() );
                Locale.setDefault(locale2);
                Configuration config2 = new Configuration();
                config2.locale = locale2;
    
                /* add preference screen */
                getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
    
                /* remove existing preferences */
                PreferenceScreen prefScreen = getPreferenceScreen();
                prefScreen.removeAll();
    
                LusilKanjiDrawPreferences.this.addPreferencesFromResource(R.xml.preferences);
                setTitle(R.string.app_name_title);
    
                /* re-add listener */   
                Preference langPref = (Preference) findPreference("langLocale");
                LusilKanjiDrawPreferences.this.setupListener( langPref );
    
                return true;
    
            }
        });
    
    }
    

    Warning: some of the methods are deprecated now. Will have to look into possible changes myself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am reading a book about Javascript and jQuery and using one of the
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.