Code example for AlertDialog

Methods: cancel

0
			public void onClick(DialogInterface dialog, int position) {
				//set the selected item 
				setSelectedMenuItem(menuItems.get(position));
				//close the menu will in turn invoke  
				//OnCancelListener where we will use this set selected menu item 
				alertDialog.cancel();
			} 
 
		}); 
 
		AlertDialog dialog = builder.create();
		dialog.setOnShowListener(new OnShowListener() {
 
			public void onShow(DialogInterface dialog) {
				setSelectedMenuItem(null); 
			} 
		}); 
		dialog.setOnKeyListener(new OnKeyListener() {
 
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
				//close the dialog if the hard menu key is pressed