AlertDialog Box in Android

it’s quite simple, here it is:

Looking like:

AlertDialog box example

AlertDialog box example

Source Code:

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

public class MainAct extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog dialog=new AlertDialog.Builder(MainAct.this).create();
dialog.setTitle(“Title”);
dialog.setMessage(“type your message here…”);
dialog.setButton(“Positive”,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
/* Do some stuff */
}
});
dialog.setButton2(“Nagative”,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
/* Do some stuff */
}
});
dialog.setButton3(“Neutral”,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
/* Do some stuff */
}
});

dialog.show();
setContentView(R.layout.main);
}
}

Share This Post

Recent Articles

© 2012 Android.PK Blog. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by Android.Pk ·