Login interface user name, password storage and re-login to automatically populate the user name, password

Source: Internet
Author: User

XML file

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.dell.wodelianxi.denglucunchu"Android:background= "@drawable/beijing"android:orientation= "Vertical" > <EditText android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter user name"Android:id= "@+id/et_user"/> <EditText android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:inputtype= "Numberpassword"Android:hint= "Please enter password"Android:id= "@+id/et_pwd"/> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" > <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Save user name, password"Android:layout_weight= "1"Android:id= "@+id/cb_jizhu"/> <Button android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Register"Android:layout_weight= "2"Android:background= "@drawable/zhuce"Android:id= "@+id/zhuce"/> <Button android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Login"Android:layout_weight= "2"Android:background= "@drawable/zhuce"Android:id= "@+id/denglu"Android:onclick= "Denglu"/> </LinearLayout></LinearLayout>

Java code

 PackageCom.example.dell.wodelianxi;Importandroid.content.SharedPreferences;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;Importandroid.text.TextUtils;ImportAndroid.view.View;ImportAndroid.widget.CheckBox;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public classDenglucunchuextendsappcompatactivity {EditText et_user;    EditText et_pwd;    CheckBox Cb_jizhu;    Sharedpreferences sp; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_denglucunchu); SP= getsharedpreferences ("info", mode_private); Et_user=(EditText) Findviewbyid (R.id.et_user); Et_pwd=(EditText) Findviewbyid (R.ID.ET_PWD); Cb_jizhu=(CheckBox) Findviewbyid (R.id.cb_jizhu); Et_user.settext (Sp.getstring ("User",NULL)); Et_pwd.settext (Sp.getstring ("Password",NULL)); }     Public voidDenglu (view view) {if(cb_jizhu.ischecked ()) {Sharedpreferences.editor Editor=Sp.edit (); String User=Et_user.gettext (). toString (); String Password=Et_pwd.gettext (). toString (); if(Textutils.isempty (user) | |textutils.isempty (password)) {Toast.maketext (Denglucunchu). This, "The user name or password cannot be empty", Toast.length_short). Show (); }            Else{editor.putstring ("User", user); Editor.putstring ("Password", password); //editor.putstring (User,password);Editor.commit (); Toast.maketext (Denglucunchu. This, "Saved successfully", Toast.length_short). Show (); }        }        Else{toast.maketext (Denglucunchu). This, "Please save user name, password", Toast.length_short). Show (); }    }}

Login interface user name, password storage and re-login to automatically populate the user name, 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.