List of usage examples for android.app AlertDialog setOnKeyListener
public void setOnKeyListener(@Nullable OnKeyListener onKeyListener)
From source file:Main.java
public static void createNonCancellableAcceptOrCancelDialog(Context context, String title, String message, String acceptButtonText, String cancelButtonText, final Runnable onAccept, final Runnable onCancel) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(false);/*from w w w .ja v a 2 s . c o m*/ builder.setTitle(title); builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton(acceptButtonText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (onAccept != null) onAccept.run(); } }); builder.setNegativeButton(cancelButtonText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (onCancel != null) onCancel.run(); } }); AlertDialog alert = builder.create(); alert.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { return true; // Pretend we processed it } return false; // Any other keys are still processed as normal } }); alert.show(); }
From source file:com.simas.vc.file_chooser.FileChooser.java
@NonNull @Override/*from ww w. j a va 2 s .c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { mAdapter = new FileChooserAdapter(); AlertDialog dialog = new AlertDialog.Builder(getActivity()).setAdapter(mAdapter, null).create(); /* Configure the dialog */ // Back listener dialog.setOnKeyListener(this); // Item click listener dialog.getListView().setOnItemClickListener(this); // Add header (up navigation) // Do it with the adapter removed, so lower APIs don't crash! dialog.getListView().setAdapter(null); View header = createHeader(dialog.getListView()); dialog.getListView().addHeaderView(header); dialog.getListView().setAdapter(mAdapter); // Show sub-files mAdapter.setFiles(getSubFiles(sCurrentPath)); return dialog; }
From source file:system.info.reader.java
public void showMyDialog(String[] valuse) { ArrayAdapter itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, valuse); View myView = getLayoutInflater().inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup_root)); ListView itemView = (ListView) myView.findViewById(R.id.PropertyList); itemView.setAdapter(itemAdapter);// ww w. j a va2s . c om itemView.setOnItemClickListener(msubitemCL); AlertDialog altDialog = new AlertDialog.Builder(this).setView(myView).create(); altDialog.setOnKeyListener(null); m_altDialog = altDialog; altDialog.show(); }
From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { _isDialogClosable = getArguments().getBoolean("closable", false); _isDialogFullscreen = getArguments().getBoolean("fullscreen", false); _isDialogCancelable = getArguments().getBoolean("cancelable", false) || _isDialogCancelable; if (_isDialogClosable) { ViewGroup view = buildInitialView(LayoutInflater.from(getActivity())); /*//from w w w . j av a 2s . com * Add this view and a close button to a wrapper view that will be used as the content view of our AlertDialog */ // unable to use the holo light theme as pre honeycomb doesn't know AlertDialog.Builder(context, theme) AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); AlertDialog dialog = adb.create(); View content = addCloseButtonToClosableDialogView(view, dialog); dialog.setView(content); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { return onBackKeyPressed(); } return false; } }); return dialog; } if (_isDialogFullscreen) { setStyle(STYLE_NO_TITLE, android.R.style.Theme); } return super.onCreateDialog(savedInstanceState); }
From source file:me.panpf.tool4a.app.MessageDialogFragment.java
/** * ?/*from w ww . j ava 2 s .c o m*/ * * @param messageDialog ? */ private void applyParams(AlertDialog messageDialog) { if (builder == null) throw new IllegalArgumentException("builder null ?setBuilder()Builder"); if (builder.message == null) throw new IllegalArgumentException("Builder.setMessage()?"); messageDialog.setTitle(builder.title); messageDialog.setMessage(builder.message); if (builder.confirmButtonName != null) { messageDialog.setButton(AlertDialog.BUTTON_POSITIVE, builder.confirmButtonName, builder.confirmButtonClickListener); } if (builder.cancelButtonName != null) { messageDialog.setButton(AlertDialog.BUTTON_NEGATIVE, builder.cancelButtonName, builder.cancelButtonClickListener); } if (builder.neutralButtonName != null) { messageDialog.setButton(AlertDialog.BUTTON_NEUTRAL, builder.neutralButtonName, builder.neutralButtonClickListener); } messageDialog.setOnKeyListener(builder.onKeyListener); messageDialog.setOnShowListener(builder.onShowListener); setCancelable(builder.cancelable); }