全部博文(43)
分类: Java
2010-08-25 13:25:28
实现代码如下:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
protected void dialog() {
AlertDialog.Builder builder = new Builder(HanderTestActivty.this);
builder.setMessage("确定要退出吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
HanderTestActivty.this.finish();
}
});
builder.setNegativeButton("取消",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
dialog();
return false;
}
return false;
}