How to display an AlertDialog in your Android application
Here is an example of an applacation, that illustrates how you can create a simple AlertDialog. The dialog can display maximum three buttons.

First of all declarate the AlertDialog type object:
- AlertDialog alertDialog = new AlertDialog.Builder(Main.this).create();
Main.this is my activity's context.
You can set your dialog's title like this:
- alertDialog.setTitle("Reset...");
And a message:
- alertDialog.setMessage("R u sure?");
Next thing, set your button(s) functions:
- alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- //here you can add functions
- } });
And you can change the icon of your AlertDialog using this line:
- alertDialog.setIcon(R.drawable.icon);
Last thing, don't forget to show your dialog:
- alertDialog.show();
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@StephanieNich10 (Stephanie Nichols)#android I laughed so hard at ochocinco 's avi. Hahahaha http://t.co/MPuhhi3m
25 weeks 3 days ago -
@CarlaAtkins8 (Carla Atkins)#android Omg! This is actually f'n interesting http://t.co/JodMOehr
25 weeks 3 days ago -
@MarianMcleod12 (Marian Mcleod)#android Precisely what song is? http://t.co/YmJXU0rB
25 weeks 3 days ago -
@JoBeach15 (Jo Beach)#android haha this made me laugh, i love ted:-) http://t.co/gtcWQ79C
25 weeks 3 days ago -
@aochart3 (青ちゃ)Start playing Paradise Island on Android http://t.co/DEID0Ao5 #Android #Androidgames #Gameinsight http://t.co/e1bifSeL
25 weeks 3 days ago
Poll
Useful resources
Android Development Projects
- 3yada for Android by tmg2000
- Nonpublic project #4538058 by Barron1408
- Targeted Jobs Push Notification System by codebarron
- Android app for a service by vmuthu
- iOS and Android app for a social website by andymediavw
- HLS-esign Delivery by hls02
- Fix Zoom and Pan and image loader in android. by DevFuture
- Implement Pushnotification into an existing app by d9n169
- Andriod Application by jasminreno
- Android App Development by Aroris



