|
Import android.app.Activity;
Import android.content.Intent;
Import android.content.SharedPreferences;
Import Android.content.SharedPreferences.Editor;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.CheckBox;
Import Android.widget.EditText;
public class Denglu extends Activity implements onclicklistener{
private EditText name;
private EditText password;
Private CheckBox box1;
Private CheckBox Box2;
Private Sharedpreferences sharedpreferences;
Private button button;
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.denglu);
Button = (button) Findviewbyid (R.id.button);
Name = (EditText) Findviewbyid (r.id.name);
Password = (EditText) Findviewbyid (R.id.password);
Box1 = (CheckBox) Findviewbyid (R.id.baocun);
Box2 = (CheckBox) Findviewbyid (R.id.zidong);
Sharedpreferences = getsharedpreferences ("Zhuce", 0);
Remember the password
Boolean IsCheckBox1 =sharedpreferences.getboolean ("CheckBox1", false);
Automatic Login
Boolean IsCheckBox2 =sharedpreferences.getboolean ("CheckBox2", false);
String names=sharedpreferences.getstring ("name", "");
String passwords=sharedpreferences.getstring ("Password", "");
if (isCheckBox1) {
if (!names.equals ("") &&!passwords.equals ("")) {
Name.settext (names);
Password.settext (Passwords);
Box1.setchecked (TRUE);
}else{
if (!names.equals ("")) {
Name.settext (names);
}
}
}
if (IsCheckBox2) {
Intent Intent = new Intent (denglu.this, Zhuye.class);
StartActivity (Intent);
}
Button.setonclicklistener (this);
}
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Switch (V.getid ()) {
Case R.id.button:
if (box1.ischecked ()) {
Sharedpreferences.edit (). Putboolean ("CheckBox1", true). commit ();
Sharedpreferences.edit (). putstring ("name", Name.gettext (). toString ()). commit ();
Sharedpreferences.edit (). putstring ("Password", Password.gettext (). toString ()). commit ();
}else{
Sharedpreferences.edit (). Putboolean ("CheckBox1", false). commit ();
Sharedpreferences.edit (). putstring ("name", Name.gettext (). toString ()). commit ();
Sharedpreferences.edit (). putstring ("Password", ""). commit ();
}
if (box2.ischecked ()) {
Sharedpreferences.edit (). Putboolean ("CheckBox2", true). commit ();
}
Intent Intent = new Intent (denglu.this, Zhuye.class);
StartActivity (Intent);
Break
Default
Break
}
}
}
|