The example in this article tells the Android Common dialog box usage. Share to everyone for your reference. Specifically as follows:
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=" displays normal dialog "
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 common 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 for the dialog box Builder.seticon (R.drawable.header);
Sets the title of the dialog box Builder.settitle ("Normal dialog box"); Set the display of the dialog box Builder.setmessage ("This is the contents of 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 contents of the normal dialog box!!
");
}
});
Create a common dialog box dialog=builder.create ();
Break
return dialog;
}
}
Run Result:
I hope this article will help you with your Android program.