protected voidShowDialog () {//determine if there is a local store password (SP string)String psd = sputil.getstring ( This, CONSTANTVALUE.MOBILE_SAFE_PSD, ""); if(Textutils.isempty (PSD)) {//1, initial Setup Password dialog boxShowsetpsddialog (); }Else{ //2, Confirm Password dialog boxShowconfirmpsddialog (); } } /*** Confirm Password dialog box*/ Private voidShowconfirmpsddialog () {//because you need to define the display style of the dialog box, you need to call Dialog.setview (view); //view is a View object XML that is converted from XML written by itself----->viewBuilder Builder =NewAlertdialog.builder ( This); FinalAlertdialog dialog =builder.create (); FinalView view = View.inflate ( This, R.LAYOUT.DIALOG_CONFIRM_PSD,NULL); //Let the dialog box display a dialog interface effect that you define yourselfDialog.setview (view); Dialog.show (); Button Bt_submit=(Button) View.findviewbyid (r.id.bt_submit); Button Bt_cancel=(Button) View.findviewbyid (r.id.bt_cancel); Bt_submit.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {EditText et_confirm_psd=(EditText) View.findviewbyid (R.ID.ET_CONFIRM_PSD); String CONFIRMPSD=Et_confirm_psd.gettext (). toString (); if(!Textutils.isempty (CONFIRMPSD)) {String psd= Sputil.getstring (Getapplicationcontext (), CONSTANTVALUE.MOBILE_SAFE_PSD, ""); if(Psd.equals (CONFIRMPSD)) {//Enter the app mobile phone anti-theft module to open a new activityIntent Intent =NewIntent (Getapplicationcontext (), testactivity.class); StartActivity (Intent); //go to the new interface to hide the dialog boxDialog.dismiss (); }Else{toastutil.show (Getapplicationcontext (),"Confirm Password Error"); } }Else{ //Prompt for user password entry has an empty conditionToastutil.show (Getapplicationcontext (), "Please enter password"); } } }); Bt_cancel.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Dialog.dismiss (); } }); } /*** Set Password dialog box*/ Private voidShowsetpsddialog () {//because you need to define the display style of the dialog box, you need to call Dialog.setview (view); //view is a View object XML that is converted from XML written by itself----->viewBuilder Builder =NewAlertdialog.builder ( This); FinalAlertdialog dialog =builder.create (); FinalView view = View.inflate ( This, R.LAYOUT.DIALOG_SET_PSD,NULL); //Let the dialog box display a dialog interface effect that you define yourselfDialog.setview (view); Dialog.show (); Button Bt_submit=(Button) View.findviewbyid (r.id.bt_submit); Button Bt_cancel=(Button) View.findviewbyid (r.id.bt_cancel); Bt_submit.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {EditText et_set_psd=(EditText) View.findviewbyid (R.ID.ET_SET_PSD); EditText ET_CONFIRM_PSD=(EditText) View.findviewbyid (R.ID.ET_CONFIRM_PSD); String PSD=Et_set_psd.gettext (). toString (); String CONFIRMPSD=Et_confirm_psd.gettext (). toString (); if(! Textutils.isempty (PSD) &&!Textutils.isempty (CONFIRMPSD)) { if(Psd.equals (CONFIRMPSD)) {//Enter the app mobile phone anti-theft module to open a new activityIntent Intent =NewIntent (Getapplicationcontext (), testactivity.class); StartActivity (Intent); //go to the new interface to hide the dialog boxDialog.dismiss (); Sputil.putstring (Getapplicationcontext (), CONSTANTVALUE.MOBILE_SAFE_PSD, PSD); }Else{toastutil.show (Getapplicationcontext (),"Confirm Password Error"); } }Else{ //Prompt for user password entry has an empty conditionToastutil.show (Getapplicationcontext (), "Please enter password"); } } }); Bt_cancel.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Dialog.dismiss (); } }); }
/res/layout/dialog_confirm_psd.xml
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <TextViewstyle= "@style/titlestyle"Android:text= "Confirm Password"Android:background= "#f30"/> <!--android:hint= "" Prompt user to enter content - <EditTextAndroid:id= "@+id/et_confirm_psd"Android:hint= "Confirm Password"Android:inputtype= "Textpassword"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"/> <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"> <ButtonAndroid:id= "@+id/bt_submit"Android:text= "Confirm"Android:layout_width= "0DP"Android:layout_weight= "1"Android:layout_height= "Wrap_content"/> <ButtonAndroid:text= "Cancel"Android:id= "@+id/bt_cancel"Android:layout_width= "0DP"Android:layout_weight= "1"Android:layout_height= "Wrap_content"/> </LinearLayout></LinearLayout>
/res/layout/dialog_set_psd.xml
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <TextViewstyle= "@style/titlestyle"Android:text= "Set Password"Android:background= "#f30"/> <!--android:hint= "" Prompt user to enter content - <EditTextAndroid:id= "@+id/et_set_psd"Android:hint= "Set Password"Android:inputtype= "Textpassword"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"/> <EditTextAndroid:id= "@+id/et_confirm_psd"Android:hint= "Confirm Password"Android:inputtype= "Textpassword"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"/> <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"> <ButtonAndroid:id= "@+id/bt_submit"Android:text= "Confirm"Android:layout_width= "0DP"Android:layout_weight= "1"Android:layout_height= "Wrap_content"/> <ButtonAndroid:text= "Cancel"Android:id= "@+id/bt_cancel"Android:layout_width= "0DP"Android:layout_weight= "1"Android:layout_height= "Wrap_content"/> </LinearLayout></LinearLayout>
Set Password dialog box