android--Remember the password

Source: Internet
Author: User

 PackageBlk4.por;Importandroid.app.Activity;ImportAndroid.content.Context;Importandroid.content.Intent;Importandroid.content.SharedPreferences;ImportAndroid.content.SharedPreferences.Editor;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.CheckBox;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public classBlk4activityextendsActivityImplementsonclicklistener{/**Called when the activity is first created.*/    PrivateEditText uname =NULL; PrivateEditText upswd =NULL; PrivateCheckBox Auto =NULL; PrivateButton login =NULL; Sharedpreferences SP=NULL;  Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.login); SP= This. Getsharedpreferences ("UserInfo", context.mode_private);    Init (); }     Public voidinit () {uname=(EditText) Findviewbyid (r.id.uname); UPSWD=(EditText) Findviewbyid (R.ID.UPSWD); Auto=(CheckBox) Findviewbyid (R.id.auto); Login=(Button) Findviewbyid (R.id.login); if(Sp.getboolean ("Auto",false) {uname.settext (sp.getstring ("Uname",NULL)); Upswd.settext (Sp.getstring ("UPSWD",NULL)); Auto.setchecked (true); } login.setonclicklistener ( This); } @Override Public voidOnClick (View v) {if(v = =login) {String name=Uname.gettext (). toString (); String pswd=Upswd.gettext (). toString (); if(Name.trim (). Equals ("") {Toast.maketext ( This, "Please enter your user name! ", Toast.length_short). Show (); return; }            if(Pswd.trim (). Equals ("") {Toast.maketext ( This, "Please enter your password! ", Toast.length_short). Show (); return; }            BooleanAutologin =auto.ischecked (); if(Autologin) {Editor Editor=Sp.edit (); Editor.putstring ("Uname", name); Editor.putstring ("UPSWD", PSWD); Editor.putboolean ("Auto",true);            Editor.commit (); }            Else{Editor Editor=Sp.edit (); Editor.putstring ("Uname",NULL); Editor.putstring ("UPSWD",NULL); Editor.putboolean ("Auto",false);                    Editor.commit ();} }}        //TODO auto-generated Method Stub}

android--Remember the password

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.