published: October 22nd, 2009
AlertDialog for Android
Are you utilizing the full potential of AlertDialog? I had no idea it was so versatile until I starting playing around with it recently. I knew you could use it for a yes/no dialog for your mobile application, but I didn’t know it could also be an About dialog. The API makes it really easy, although it doesn’t seem like the setPositiveButton() method is in the Android documentation. The code snippet below cuts it down to the bare minimum. It appears that a null can be passed instead of an empty OnClickListener and the action simply closes the window…which is the desired effect.
AlertDialog.Builder ad = new AlertDialog.Builder( this );
ad.setTitle( "About My Mobile Application" );
ad.setMessage( "This text explains My Mobile Application, thanks for " +
"purchasing it from the Android Market!" );
ad.setPositiveButton( "OK", null );
ad.show();
I’ve recently cleaned up a bunch of my code with this simple Dialog. And next I may have to look into the FrameLayout feature mentioned in the Android documentation.
