這是我的MainActivity中代碼的一部分。 stopwatch1是調用MainActivity圖像按鈕:故意或意外退出對話後終止音頻
stopwatch1 = (ImageButton)findViewById(R.id.stopwatch1);
我試圖尋找關於如何使用dialog.setOnDismissListener線索,但是,也有不正確的答案,幫助我的聲音後故意殺害或意外退出對話框。任何幫助,將不勝感激。
stopwatch1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog mmDialog1 = new Dialog(context);
mmDialog1.setContentView(R.layout.countdowntimer);
mmDialog1.setTitle("Stop-watch");
Button ddButton1 = (Button) mmDialog1.findViewById(R.id.countdown_exit);
final Button ddButton2 = (Button) mmDialog1.findViewById(R.id.countdown_start);
final TextView timeview = (TextView) mmDialog1.findViewById(R.id.timeview);
ddButton2.setTag(1);
ddButton2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final int status = (Integer) v.getTag();
if (status == 1) {
ddButton2.setText("Stop");
countDownTimer = new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
int time = (int) (millisUntilFinished/1000);
timeview.setText(Integer.toString(time));
}
@Override
public void onFinish() {
timeview.setText("60");
ddButton2.setText("Start");
MediaPlayer stop = MediaPlayer.create(context, R.raw.stop);
stop.start();
}
}.start();
v.setTag(0);
} else {
ddButton2.setText("Start");
timeview.setText("60");
countDownTimer.cancel();
v.setTag(1);
}
}
});
ddButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mmDialog1.dismiss();
}
});
mmDialog1.show();
}
});