Main. xml layout File
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<EditText android: text = ""
Android: id = "@ + id/editText"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: editable = "false"
Android: cursorVisible = "false"/>
<Button android: text = "show normal dialog box"
Android: id = "@ + id/button"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>
</LinearLayout>
AlertDialog class
Package com. ljq. dialog;
Import android. app. Activity;
Import android. app. Dialog;
Import android. app. AlertDialog. Builder;
Import android. content. DialogInterface;
Import android. content. DialogInterface. OnClickListener;
Import android. OS. Bundle;
Import android. view. View;
Import android. widget. Button;
Import android. widget. EditText;
Public class AlertDialog extends Activity {
Private EditText editText;
Private final static int DIALOG = 1;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
EditText = (EditText) findViewById (R. id. editText );
Button button = (Button) findViewById (R. id. button );
Button. setOnClickListener (new View. OnClickListener (){
Public void onClick (View v ){
// Display dialog box
ShowDialog (DIALOG );
}
});
}
/**
* Create normal dialog box
*/
@ Override
Protected Dialog onCreateDialog (int id ){
Dialog dialog = null;
Switch (id ){
Case DIALOG:
Builder builder = new android. app. AlertDialog. Builder (this );
// Set the icon in the dialog box
Builder. setIcon (R. drawable. header );
// Set the title of the dialog box
Builder. setTitle ("normal dialog box ");
// Set the display content of the dialog box
Builder. setMessage ("this is the content in the normal dialog box !! ");
// Add button, android. content. DialogInterface. OnClickListener. OnClickListener
Builder. setPositiveButton ("OK", new OnClickListener (){
Public void onClick (DialogInterface dialog, int which ){
EditText. setText ("this is the content in the normal dialog box !! ");
}
});
// Create a normal dialog box
Dialog = builder. create ();
Break;
}
Return dialog;
}
}
Running result