Wednesday, September 28, 2011

Android Simple AlertDialog Example

SIMPLE ALERTDIALOG SOURCE CODE is

package com.AlertDialogExample;
import android.app.Activity; import android.app.AlertDialog; import and
roid.content.DialogInterface; import android.os.Bundle;
public class AlertDialogExample extends Activity {
@Override

protected void onCreate(Bundle sav
edInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog.Builder adb = new AlertDialog.Builder(this);

adb.setTitle("Set Title he
re");
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 dia
log, int id)
{
// Action for 'Cancel' Button
dialog.cancel();
}
});
adb.setIcon(R.drawable.icon);
adb.show();
}
}




No comments:

Post a Comment