逻辑错误,或对String值的误解

时间:2015-01-19 16:44:52

标签: java android

这些适用于Android应用。这很难理解。 :

.... playmusic(测试);

protected void playmusic(String theText) {    
        if (mp != null) {
        mp.reset();
        mp.release();
    }
    if (theText == "1") {
        mp = MediaPlayer.create(this, R.drawable.sound1);
    } else if (theText == "3") {
        mp = MediaPlayer.create(this, R.drawable.sound3);
    } else if (theText == null) {
        mp = MediaPlayer.create(this, R.drawable.sound5);
    } else if (theText == "2") {
        mp = MediaPlayer.create(this, R.drawable.sound3);
    } else
        mp = MediaPlayer.create(this, R.drawable.sound4);
    mp.start();
Toast.makeText(getBaseContext(), "show theText--" + theText+"--",
            Toast.LENGTH_SHORT).show();

}    

首先,我设置:set = String.valueOf(a); (我从其他活动中拿了一个,a = 1) ...然后我在手机中收到了这些内容: 显示文本 - 1-- 但它播放声音:sound4.mp3

谢谢!

0 个答案:

没有答案