Android instance-Mobile security Defender (12)-Make Input Password dialog box and set corresponding Click event

Source: Internet
Author: User

First, the goal.

Customize the Enter Password dialog box, judging by the password you enter and the password you have saved.

Second, the code implementation.

1, the tenth section of the method to customize a password to enter the dialog box.

2. Set the Click event for the button, mainly about the click event of the "Confirm" button.

①. Get the text through the TextView object's GetText () and convert it to a string via ToString () and remove the space by trimming () to get the input password of the string object;

②. Obtains the saved password through the Sharedpreferences object's GetString (string key, String defvalue), the parameter String key is the name of the key;

③. According to the input password and obtain the saved password to judge, and according to the situation after the decision to operate accordingly.

Enter the code for the Password dialog box:

1 protected voidShowinputpwddialog () {2Alertdialog.builder Builder =NewBuilder (homeactivity. This);3View view = View.inflate ( This, R.layout.inputpwddialog,NULL);4Inputpwddialog_et_pwd =(TextView) View5 . Findviewbyid (r.id.inputpwddialog_et_pwd);6inputpwddialog_bt_conf =(Button) View7 . Findviewbyid (r.id.inputpwddialog_bt_conf);8Inputpwddialog_bt_cancel =(Button) View9 . Findviewbyid (r.id.inputpwddialog_bt_cancel);Ten         //Set click on "Cancel" to make the dialog disappear. OneInputpwddialog_bt_cancel.setonclicklistener (NewOnclicklistener () { A  - @Override -              Public voidOnClick (View v) { the Alertdialog.dismiss (); -             } -         }); -         //set the Listen event for the OK button +Inputpwddialog_bt_conf.setonclicklistener (NewOnclicklistener () { -  + @Override A              Public voidOnClick (View v) { at                 //get the password in the input box -String Inputpassword =Inputpwddialog_et_pwd.gettext () - . toString (). Trim (); -                 //get the password stored in the config file -String Savedpassword = sp.getstring ("Password", "" "); -                 //complete related operations based on two password comparisons in                 if(Textutils.isempty (Inputpassword)) { -Toast.maketext (homeactivity. This, "Enter password is empty", 0). Show (); to}Else if(Inputpassword.equals (Savedpassword)) { + Alertdialog.dismiss (); -Toast.maketext (homeactivity. This, "Password entered correctly, go to Main page", 0). Show (); the}Else { *Toast.maketext (homeactivity. This, "Password input error", 0). Show (); $Inputpwddialog_et_pwd.settext ("");Panax Notoginseng                     return; -                 } the             } +         }); A Builder.setview (view); theAlertdialog =builder.show (); +}
View Code

Android instance-Mobile security Defender (12)-Make Input Password dialog box and set corresponding Click event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.