0

我想处理按钮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;
}
4

1 回答 1

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);
}
于 2012-08-13T15:19:33.553 回答