我想处理按钮onBack
,这样当按下它时,会出现AlertDialog
,以便onBack按钮的压力,你将变量设置为-1。
这是我的提醒对话框的代码:
protected Dialog onCreateDialog(int id)
{
switch(id)
{
case CUSTOM_DIALOG:
AlertDialog.Builder builder1;
builder1 = new AlertDialog.Builder(SecondaAttivita.this);
builder1.setView(layout);
builder1.setCancelable(true);
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(testo.getWindowToken(), 0);
testo.setInputType(0);
alertDialog1 = builder1.create();
break;
default:
alertDialog1.dismiss();
alertDialog1 = null;
}
return alertDialog1;
}
答案 0 :(得分:0)
您可以通过在活动类
中使用以下代码来回退智能手机的按钮事件public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
//Action against pressing back button here
return true;
}
return super.onKeyDown(keyCode, event);
}