-1

Android プログラムの一部に次のコードを書きましたが、期待どおりに動作せず、代わりに変数 message_2 の内容を出力するだけです。以下は私のコードです

public void sendCall(View view){
    Intent intent1 = new Intent(this, DisplayCallActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);

    String message_2 = editText.getText().toString();
    String message = "Mahesh";
    //String message_1 = "Kumar";

    if (message_2 == "M")
    {
        intent1.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent1);
    }
    else
    {
        intent1.putExtra(EXTRA_MESSAGE, "Unknown");
        startActivity(intent1);
    }

これに関する任意の助けをいただければ幸いです

ありがとう

4

2 に答える 2

3

Java では、文字列を==. 以下を使用する必要があります。

message_2.equals("M")
于 2012-10-03T17:50:01.963 に答える
0

このようにあなたの状態を変更しますif(message_2.equals("M"))

于 2012-10-03T17:50:30.053 に答える