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)) {
// 给 用户提示, 输入 号码 和 密码
Toast.makeText(this, "请输入 qq号码 和密码 ", 0).show();
return;
}
else {
sp =getSharedPreferences("config", 0);
Editor editor=sp.edit();
editor.putString("number", number);
editor.putString("password", password);
editor.commit();
}
}
}