1 Packagecom.example.myandroid01;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.os.Bundle;5 ImportAndroid.view.Menu;6 ImportAndroid.view.MenuItem;7 ImportAndroid.view.View;8 ImportAndroid.widget.Button;9 ImportAndroid.widget.Toast;Ten /** One * Android Package Dialog A * @Describe: - * @package: com.example.myandroid01 - * @authorshaobn the * @date 2015-9-14 pm 2:35:49 - */ - Public classMainactivityextendsactionbaractivity { - PrivateButton button1; + PrivateButton button2; - PrivateCustomdialog Cdcustomdialog; + Private Static FinalString TITLE = "Warning"; A Private Static FinalString MESSAGE = "OK delete?" "; at Private Static FinalString buttonname = "OK"; - @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -Button1 = (Button) This. Findviewbyid (r.id.button1); inButton2 = (Button) This. Findviewbyid (r.id.button2); -Button1.setonclicklistener (NewView.onclicklistener () { to + @Override - Public voidOnClick (View arg0) { the //TODO auto-generated Method Stub *Cdcustomdialog =NewCustomdialog (mainactivity. This); $Cdcustomdialog.createdialog (Title,message, ButtonName,NewDialoginter () {Panax Notoginseng - @Override the Public voidCallbackBooleanflag) { + //TODO auto-generated Method Stub AToast.maketext (Getapplicationcontext (), "clicked", 1). Show (); the } + }); - } $ }); $Button2.setonclicklistener (NewView.onclicklistener () { - - @Override the Public voidOnClick (View arg0) { - //TODO auto-generated Method StubWuyiCdcustomdialog =NewCustomdialog (mainactivity. This); theCdcustomdialog.toastdialog ("Sure"); - } Wu }); - } About}
1 Packagecom.example.myandroid01;2 3 ImportAndroid.app.AlertDialog;4 ImportAndroid.content.Context;5 ImportAndroid.content.DialogInterface;6 ImportAndroid.content.DialogInterface.OnClickListener;7 ImportAndroid.widget.Toast;8 /**9 * Custom Dialog ClassTen * @Describe: One * @package: com.example.myandroid01 A * @authorshaobn - * @date 2015-9-14 pm 2:36:17 - */ the classCustomdialog { - Privatecontext context; - PrivateAlertdialog.builder Builder; - PublicCustomdialog (Context context) { + //TODO auto-generated Constructor stub - This. Context =context; + } A Public voidCreatedialog (String title,string message,string buttonname,FinalDialoginter Dialoginter) { atBuilder =NewAlertdialog.builder (context); - Builder.settitle (title); - builder.setmessage (message); -Builder.setpositivebutton (ButtonName,NewOnclicklistener () { - - @Override in Public voidOnClick (Dialoginterface arg0,intarg1) { - //TODO auto-generated Method Stub toDialoginter.callback (true); + } - }); the builder.create (). Show (); * } $ Public voidtoastdialog (String message) {Panax Notoginseng Toast.maketext (context, Message,toast.length_long). Show (); - } the + } A Interfacedialoginter{ the voidCallbackBooleanflag); +}
Android Package Dialog