title: Set Locale with RadioButton Android
body: <p>I am trying to Change Language in App using Locale. I have two <code>radioButton</code> within <code>RadioGroup</code>. When I try to change the Language, <code>setOnCheckedChangeListener</code> keep on Calling continuously. If I remove the Locale code, it is working fine</p>
  
  <pre><code> Locale locale;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      RadioGroup radioGroup = (RadioGroup) findViewById(R.id.toggle);
  
  
      Toast.makeText(this, ""+getString(R.string.app_name), Toast.LENGTH_SHORT).show();
  
      radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(RadioGroup group, int checkedId) {
              RadioButton rb = (RadioButton) group.findViewById(checkedId);
              Toast.makeText(MainActivity.this, "Inside", Toast.LENGTH_SHORT).show();
              if (rb!=null){
                  switch(checkedId) {
                      case R.id.rdEnglish:
                          // do operations specific to this selection
                          locale = new Locale("en");
                          rb.setChecked(true);
                          setLocale();
                          break;
                      case R.id.rdTamil:
                          // do operations specific to this selection
                          locale = new Locale("ta");
                          setLocale();
                          break;
  
                      default:
                          locale = new Locale("en");
                           setLocale();
                  }
  
              }
          }
      });
  
  }
  
  
  
  public void setLocale() {
  
      Locale.setDefault(locale);
      Configuration configuration = new Configuration();
      configuration.locale = locale;
      getBaseContext().getResources().updateConfiguration(configuration,getBaseContext().getResources().getDisplayMetrics());
      recreate();
  }
  </code></pre>
  
  <p>}</p>