我有一个奇怪的问题。当我运行应用程序并单击按钮(btn_eng 或 btn_pl)时,我看到登录 logcat(“擦除对话框”或“擦除对话框 PL”),但是下次当我单击它时它不会显示并且按钮不会执行其 onClick 操作. 我试图制作按钮来改变语言。在我的应用程序中,我有一个包含数据表单资源(字符串数组)的对话框,当我更改语言时,我想要擦除对话框并使用足够的数据创建新的对话框。
//public static Activity act; -> before onCreate(..)
this.act = this;
Button btn_eng = (Button) findViewById(R.id.btnEN);
btn_eng.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("XXX", "Erase dialog");
act.removeDialog(1);
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = act.getBaseContext().getResources().getConfiguration();
config.locale = locale;
act.getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
act.setContentView(R.layout.main);
}
});
Button btn_pl = (Button) findViewById(R.id.btnPL);
btn_pl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("XXX", "Erase dialog PL");
act.removeDialog(1);
Locale locale = new Locale("pl");
Locale.setDefault(locale);
Configuration config = act.getBaseContext().getResources().getConfiguration();
config.locale = locale;
act.getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
act.setContentView(R.layout.main);
}
});