Android Simple AlertDialog Example - ANDROID - Helper

Monday, April 11, 2011

Android Simple AlertDialog Example


SIMPLE ALERTDIALOG

SOURCE CODE is

package com.AlertDialogExample;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class AlertDialogExample extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
               
                AlertDialog.Builder adb = new AlertDialog.Builder(this);
                adb.setTitle("Set Title here");
                adb.setMessage("Set the Text Message here");
                adb.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
// Action for 'Ok' Button
                                }
                });
                adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
                                public void onClick(DialogInterface dialog, int id)
                                                {
                                                // Action for 'Cancel' Button
                                                dialog.cancel();
                                }
                });
                adb.setIcon(R.drawable.icon);
adb.show();
}
}

The OUTPUT will be


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2H-ji_2q0WBe4iUDIXdEFjPias5xa166VwUlSC13iMRmJnUUqukEjrijp4SKqDpBk5DXs2bQWIi9PL69u9sAmOZpJtgbG2YBJP4sW5aKTfc4Xje9A1QV4u20ykobxbtf0GI50S0n5bD8/

3 comments: