Code example for AlertDialog.Builder

Methods: create, setNegativeButton, setPositiveButton, setTitle, show

0
 
		return super.onOptionsItemSelected(item);
	} 
 
	private void createDialog() { 
		Builder dialog = new AlertDialog.Builder(this);
		dialog.setTitle("AlartDialog");
 
		dialog.setPositiveButton("OK", new OnClickListener() {
 
			@Override 
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(MainActivity.this, "OK", Toast.LENGTH_SHORT);
			} 
		}); 
 
		dialog.setNegativeButton("Cancel", new OnClickListener() {
 
			@Override 
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT);
			} 
		}); 
 
		dialog.create();
		dialog.show();
	} 
 
	private View getViewFromLayout(Context context, int layout) {
		LayoutInflater mInflater = LayoutInflater.from(context);
		View view = mInflater.inflate(layout, null);
Stop searching for code, let great code find you!  Add Codota to your java IDE