-1

以下のコードを使用してselectediemテキストを取得します。選択されたものに基づいて何かを表示するのが好きですが、一致しないのは奇妙です。手がかりはありますか?

Spinner mlogin_store;
mlogin_store = (Spinner) findViewById(R.id.spinlogin_store);
String Text = mlogin_store.getSelectedItem().toString().trim(); 

Log.d("click",Text);  //I can see the "Abc" in LogCat. but it doesn't match the string    below. 
if (Text=="Abc"){  //first block
//Do something 
}else{
//do something else}
4

2 に答える 2

0

Text. equals("Abc") を使用する

あなたのコードを今すぐ

Spinner mlogin_store;
    mlogin_store = (Spinner) findViewById(R.id.spinlogin_store);
    String Text = mlogin_store.getSelectedItem().toString().trim(); 

    Log.d("click",Text);  //I can see the "Abc" in LogCat. but it doesn't match the string    below. 
    if (Text.equals("Abc")){  //first block
    //Do something 
    }else{
        //do something else
}
于 2013-03-01T06:58:29.947 に答える
0

文字列を==と比較しないでください。比較には常に文字列関数を使用します。

if (Text.equalsIgnoreCase("Abc"))
{  
     //first block
     //Do something 
}
else
{
    //do something else}
}

equalsIgnoreCase 関数 文字の大文字と小文字を無視して、指定された文字列とこの文字列を比較し、等しい場合は true を返します。

于 2013-03-01T07:01:21.470 に答える