Android AlertDialog 实例

 

public  boolean onKeyDown( int keyCode, KeyEvent event)
    {
         if(keyCode == KeyEvent.KEYCODE_BACK)
        {
            AlertDialog.Builder alert =  new AlertDialog.Builder(cxt);
            alert.setTitle("退出提示");
            alert.setMessage("确认退出吗?");
            alert.setNegativeButton("取消",  new DialogInterface.OnClickListener() {
                
                @Override
                 public  void onClick(DialogInterface dialog,  int which) {
                     //  TODO Auto-generated method stub
                    
                }
            });
            alert.setPositiveButton("确认",  new DialogInterface.OnClickListener() {
                
                @Override
                 public  void onClick(DialogInterface dialog,  int which) {
                    System.exit(0);                    
                }
            });
            alert.show();
        }
         return  false;
    }

 

xtc在类里面定义private Context cxt = null;

你可能感兴趣的:(AlertDialog)