Back key를 눌렀을때, 종료 확인창을 출력..
한번 더누르면 종료 처리..
@Override
protected Dialog onCreateDialog(int id) {
switch(id)
{
case DIALOG_QUIT:
return new AlertDialog.Builder(this)
.setMessage("Are you sure you want to leave the game?")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey (DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {
dialog.dismiss();
finish();
return true;
}
return false;
}
}).create();
//break;
default:
break;
}
return null;
}
댓글 없음:
댓글 쓰기