I have an android app and i have different activities and in that activities i have different textviews. I have two buttons of two languages one for English and another for chinese. Now i want to change all the textviews from different activities in another language as soon as user press chinese language.
Here is my one activity...
public class AndroidLocalize extends Activity {
TextView tv;
Button b1,b2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
tv.setText(R.string.greet);
}
});
b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Locale locale = new Locale("hi");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
tv.setText(R.string.greet);
}
});
}
I am able to chnage the language on button click in the same activity now i want to chnage the language in another activity also. here is my another activity..
public class Laanguage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.language);
TextView tv;
tv = (TextView) findViewById(R.id.textView2);
}