0

我不知道为什么会发生这种情况,因为我以前的代码是这样的,但是当我的活动继续进行时,应用程序将停止 id 0 的键盘。

public class Lesson_p extends Activity implements OnClickListener {
MediaPlayer p, p_sound;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lesson_p);
    p = MediaPlayer.create(this, R.raw.p);
    p_sound = MediaPlayer.create(this, R.raw.p_sound);

    View p = findViewById(R.id.imageButton_p);
    p.setOnClickListener((OnClickListener)this);

    View p_sound = findViewById(R.id.imageButton_pp);
    p_sound.setOnClickListener((OnClickListener)this);

    Button back = (Button) findViewById(R.id.button_bckp);
    back.setOnClickListener((OnClickListener)this);

    Button next = (Button) findViewById(R.id.button_nxtp);
    next.setOnClickListener((OnClickListener)this);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
     switch(v.getId()){
        case R.id.imageButton_p:
            p.start();
            break;

        case R.id.imageButton_pp:
            p_sound.start();
            break;

        case R.id.button_bckp:
            Intent back = new Intent(this, Example_n.class);
            startActivity(back);
            break;

        case R.id.button_nxtp:
            Intent next = new Intent(this, Example_p.class);
            startActivity(next);
            break;

        }       

}
//@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    p.release();
    p_sound.release();
}
}    
4

1 回答 1

1

检查这篇文章。它会给你答案。要获得谷歌的答案,请点击这里

于 2012-08-30T12:50:21.753 回答