See this thread: http://groups.google.com/group/android-developers/browse_thread/thread/992a402e25904250/7c0804dc7ee8ea5b
Apparently the default implementation of AlertDialog will ALWAYS call dismiss when you click a button. <http://groups.google.com/group/android-developers/browse_thread/thread/992a402e25904250/7c0804dc7ee8ea5b>To do validation you may have to extend AlertDialog or set a custom view on the Dialog with a set of buttons you have control over. ------------------------------------------------------------------------------------------------- TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking On Sat, Dec 26, 2009 at 6:24 PM, Carl Whalley <[email protected]>wrote: > I have a handler for the custom onClick thus: > > public class DialogValidator implements OnClickListener { > private int id; > private Activity activity; > > protected DialogValidator(Activity activity, int id) { > this.activity = activity; > this.id = id; > } > > @Override > public void onClick( DialogInterface dialog, int whichButton ) > { > if (whichButton == AlertDialog.BUTTON_POSITIVE) { > Toast.makeText(activity, "Ok from DialogValidator", > Toast.LENGTH_SHORT).show(); > } else { > activity.dismissDialog(id); > } > } > } > > And implement it like this: > > @Override > protected Dialog onCreateDialog( int id ) { > ... > return new AlertDialog.Builder( this ) > .setIcon( R.drawable.icon ) > .setTitle( R.string.dialog_title ) > .setView( dialogView ) > .setPositiveButton( R.string.button_ok, new DialogValidator > (activity, id)) > .setNegativeButton(R.string.button_cancel, new > DialogInterface.OnClickListener() { > public void onClick(DialogInterface dialog, int whichButton) > { > } > }) > .create(); > } > > I see the Toast but the dialog is dismissed anyway when you click Ok. > In a fuller version I want > to access some of the input fields and only dismiss this dialog if > they are valid. To do that I'd flesh out > the above code where the Toast is - but need it to not dismiss itself. > If I have overriden the parents' > onClick() method as seen, and we know it is being called, why does it > still do that? > > Android Academy - http://www.androidacademy.com > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

