Code example for AlertDialog.Builder

Methods: setOnKeyListener, setView

0
        	LinearLayout.LayoutParams.WRAP_CONTENT));
        layout.setMinimumWidth(200);
        TextView tv = new TextView(context);
        tv.setText("Press a key!");
        layout.addView(tv);
        builder.setView(layout); 
        builder.setOnKeyListener(this);
        super.onPrepareDialogBuilder(builder);
	} 
 
	public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
		if (event.getAction() == KeyEvent.ACTION_UP) {
			for(int d=0;d<deniedKeyCode.length;d++) {
				if (keyCode == deniedKeyCode[d])
					return false; 
			} 
			// maj pref 
			SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
			//sp.getInt(prefKey, defaultKeyCode); 
			Editor e = sp.edit();
Contextual code suggestions in your IDE  Get Codota for Java