按钮的文字没有改变

Text of buttons are not changing

我试图通过变量(语言)更改文本,但即使语言变量的值为 "albanian",按钮的文本也没有改变!

P.S 变量值是从另一个 activity.

传递过来的
String language="";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_level_activity_layout);

    btnBegginer=(Button)findViewById(R.id.btnBegginer);
    btnMedium=(Button)findViewById(R.id.btnMedium);
    btnHard=(Button)findViewById(R.id.btnHard);

    Intent objIntent=getIntent();
    language=objIntent.getStringExtra("language");

    //Toast.makeText(getApplicationContext(),language,Toast.LENGTH_LONG).show();

    if (language=="albanian")
    {
        btnBegginer.setText("FILLESTAR");
        btnMedium.setText("MESATARE");
        btnHard.setText("VESHTIRE");
    }
    else
    {
        btnBegginer.setText("BEGGINER");
        btnMedium.setText("MEDIUM");
        btnHard.setText("HARD");
    }

比较 Java 中的字符串时使用 equals() 方法。例如:stringValue.equals("Test") return true/false.

永远不要使用 == 来比较字符串 使用 .equals()

if (language.equals("albanian"))
{
    btnBegginer.setText("FILLESTAR");
    btnMedium.setText("MESATARE");
    btnHard.setText("VESHTIRE");
}
else
{
    btnBegginer.setText("BEGGINER");
    btnMedium.setText("MEDIUM");
    btnHard.setText("HARD");
}