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 8125629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:52:52+00:00 2026-06-06T06:52:52+00:00

I have 3 buttons to change language. So I need to make method, where

  • 0

I have 3 buttons to change language. So I need to make method, where I could set listeners to buttons which could change language everytime they are pressed.
I tried this https://stackoverflow.com/a/2900144/1088229 but this way it changes locale only once and seems that this doesn’t work any more (if i click again, it doesn’t even respond). So I added changeLanguageListener() in end of listener, so listener is refreshed.

So is it ok, how i solved it or there is another way?

private void changeLanguageListener() {
    final Button butEn = (Button) findViewById(R.id.button_language_en);
    final Button butLt = (Button) findViewById(R.id.button_language_lt);
    final Button butRu = (Button) findViewById(R.id.button_language_ru);
    OnClickListener listener = new OnClickListener() {

        public void onClick(View v) {
            Button but = (Button) v;
            Resources res = getResources();
            String current = res.getConfiguration().locale.getCountry();
            Log.i("Current", current);
            String localeString = new String(current);
            if (but.equals(butEn)) {
                localeString = "en";
            } else if (but.equals(butLt)) {
                localeString = "lt";
            } else if (but.equals(butRu)) {
                localeString = "ru";
            }
            Log.i("Clicked", localeString);

            if (!current.equalsIgnoreCase(localeString) && localeString.length() > 0) {
                // Change locale settings in the app.
                DisplayMetrics dm = res.getDisplayMetrics();
                android.content.res.Configuration conf = res.getConfiguration();
                conf.locale = new Locale(localeString.toLowerCase());
                res.updateConfiguration(conf, dm);  
                //refresh menu
                setGridView();
                //added this line to get refreshed listener
                changeLanguageListener();
            }               
        }
    };
    butEn.setOnClickListener(listener);
    butLt.setOnClickListener(listener);
    butRu.setOnClickListener(listener);
}
  • 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-06-06T06:52:54+00:00Added an answer on June 6, 2026 at 6:52 am

    So, because of only two activities (two menu modes) where i let to change locale, I just restart Activity right after locale change, so everything is refreshed. Didn’t find any other better solution

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

Sidebar

Related Questions

I have following code which works for radio buttons but need to be changed
I have a Datagrid , 2 textBoxes and 4 buttons whenever I change positions
I have a button, the label of which I want to change back and
I want to have buttons that kind of act like tabs - they switch
Basically i have 6 labels acting as buttons. When they are clicked on, they
I have a preferences activity where I can change the language and the theme
I have to change the Yes and No buttons in an Alert.show(..), to another
Is there any way with jQuery-Mobile to change the language of the buttons displayed
I have the following jQuery code to make my checkboxes act like radio buttons,
I need to make an application in which the user can toggle between two

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.