更改语言环境后,按钮不起作用

时间:2014-02-16 21:55:34

标签: android locale

我正在做一个项目,我想在应用程序的操作栏中放置一个翻译按钮。问题是,在我单击按钮(并且它翻译按钮中的文本)后,我分配给按钮的所有其他东西都不起作用。这是我的Locale的代码

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        if (item.getItemId() == R.id.trans) {

            Toast t = Toast.makeText(this, "Translation", Toast.LENGTH_LONG);
            t.show();

            Locale mLocale = new Locale("bg");
            Locale.setDefault(mLocale);
            Configuration config = getBaseContext().getResources()
                    .getConfiguration();
            if (!config.locale.equals(mLocale)) {
                config.locale = mLocale;
                getBaseContext().getResources().updateConfiguration(config,
                        null);
                setContentView(R.layout.activity_main);
            } else {
                mLocale = new Locale("en");
                config.locale = mLocale;
                getBaseContext().getResources().updateConfiguration(config,
                        null);
                setContentView(R.layout.activity_main);

            }
        }

        return super.onOptionsItemSelected(item);
    }

and this is my onClick listener 

public void onClick(View v) {

        if (v.getId() == lBtn.getId()) {

            startActivity(new Intent(this, lect.class));

        } else if (v.getId() == sBtn.getId()) {
            Toast t = Toast.makeText(this, "Text",
                    Toast.LENGTH_LONG);
            t.show();
        } else if (v.getId() == cBtn.getId()) {

            Toast t = Toast.makeText(this,
                    "Text",
                    Toast.LENGTH_LONG);
            t.show();
        } else if (v.getId() == aBtn.getId()) {

            Toast t = Toast.makeText(this, "Text",
                    Toast.LENGTH_LONG);
            t.show();
        }

    }

你知道如何修复它吗?谢谢你,祝你有愉快的一天:)

0 个答案:

没有答案