@Override protected void showDialog(Bundle state) { super.showDialog(state); // If the dialog isn't an instance of alert dialog this code is useless if (super.getDialog() instanceof AlertDialog) { final AlertDialog theDialog = (AlertDialog) super.getDialog(); // get originalBottomPadding to know when adjust the underlying // layouts bottom padding (ie has room already // been created for an error message) int padding = Integer.MIN_VALUE; try { padding = ((LinearLayout) getEditText().getParent()) .getPaddingBottom(); } catch (Exception e) { // some exception thrown. Unable to do increase space for error // message } final int originalBottomPadding = padding; Button b = theDialog.getButton(AlertDialog.BUTTON_POSITIVE); // attach our validating on click listener ValidatingOnClickListener l = new ValidatingOnClickListener( originalBottomPadding, theDialog); b.setOnClickListener(l); // add an editor action listener for the 'done/next' buttons on a // soft keyboard getEditText().setOnEditorActionListener(l); } }
/** * Popup currencies options. * @param pReportReferenceCurrency * @return */ private boolean showChoiceList(final EditTextPreference pReportReferenceCurrency) { new AlertDialog.Builder(ReportPreferencesActivity.this) .setTitle(R.string.report_reference_currency) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(){ // get user preferred currency @Override public void onClick(DialogInterface dialog, int which) { pReportReferenceCurrency.setText(currency); } }) .setSingleChoiceItems(currencies, selectedCurrenceIndex, new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { selectedCurrenceIndex = which; currency = currencies[which]; } }) .show(); Dialog dialog = pReportReferenceCurrency.getDialog(); if(dialog!=null) dialog.cancel(); return true; }
@Override public boolean onPreferenceClick(Preference preference) { // don't show default dialog startDirPref.getDialog().dismiss(); File startDirVal = LoadPrefsUtil.startDir(startDirPref.getSharedPreferences()); logger.debug("using initial start dir val: {}", startDirVal); Intent dirPickerIntent = Defaults.createDefaultDirPicker(getActivity().getApplicationContext(), startDirVal); startActivityForResult(dirPickerIntent, 0); return false; } });
Dialog dialog = ((EditTextPreference)preference).getDialog(); if(dialog != null) dialog.dismiss();