Package com.itheima.share;
Import Android.os.Bundle;
Import android.app.Activity;
Import android.content.SharedPreferences;
Import Android.content.SharedPreferences.Editor;
Import Android.text.TextUtils;
Import Android.view.Menu;
Import Android.view.View;
Import Android.widget.CheckBox;
Import Android.widget.EditText;
Import Android.widget.Toast;
public class Mainactivity extends Activity {
Private EditText Ed_qqnumber;
Private EditText Ed_qqpassword;
Private CheckBox CBX;
Private Sharedpreferences sp;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Ed_qqnumber = (EditText) Findviewbyid (R.id.qqnumber);
Ed_qqpassword = (EditText) Findviewbyid (R.id.qqpassword);
CBX = (CheckBox) Findviewbyid (R.id.remember);
SP = getsharedpreferences ("config", mode_private);
String num = sp.getstring ("number", "");
String pwd = sp.getstring ("Password", "" ");
Ed_qqnumber.settext (num);
Ed_qqpassword.settext (PWD);
}
public void Login (View v) {
String number = Ed_qqnumber.gettext (). toString (). Trim ();
String password = Ed_qqpassword.gettext (). toString (). Trim ();
if (textutils.isempty (number) | | Textutils.isempty (password)) {
Give user prompt, enter number and password
Toast.maketext (This, "Please enter QQ number and password", 0). Show ();
Return
}
else {
SP =getsharedpreferences ("config", 0);
Editor Editor=sp.edit ();
Editor.putstring ("number", number);
Editor.putstring ("password", password);
Editor.commit ();
}
}
}
Android XML File parsing (getsharedpreferences)