標籤
- C
- android
- Objective-c
- Sort
- BlueTooth
- Python
- 133
- Apache
- ArrayList
- BluetoothChat
- C sharp
- C#
- CVS
- CheckBox
- Closest Pair
- Console.ReadLine
- HashMap
- NFC
- NSDocumentDirectory
- NSString
- Pandaboard
- SQLite
- UIAlertController
- VB
- Xcode6
- driver
- execSQL
- gatt error
- httpd.conf
- office
- primie check
- property
- sharedApplication
- 小小問題
2013年4月29日 星期一
[Android] remember me checkbox
private CheckBox checkBox;
SharedPreferences login_pref;
private SharedPreferences.Editor loginPrefsEditor;
private Boolean saveLogin;
// onCreate
username = (EditText) findViewById(R.id.editText_username);
password = (EditText) findViewById(R.id.editText_password);
login = (Button) findViewById(R.id.button_login);
checkBox = (CheckBox)findViewById(R.id.checkBox1);
login.setOnClickListener(this);
login_pref = getSharedPreferences("loginPrefs", MODE_PRIVATE);
loginPrefsEditor = login_pref.edit();
saveLogin = login_pref.getBoolean("saveLogin", false);
if (saveLogin == true) {
username.setText(login_pref.getString("username", ""));
password.setText(login_pref.getString("password", ""));
checkBox.setChecked(true);
}
//onClick
if (v == login)
{
Activity = new Intent();
name = username.getText().toString();
pwd = password.getText().toString();
//Commit login information
if (checkBox.isChecked()) {
loginPrefsEditor.putBoolean("saveLogin", true);
loginPrefsEditor.putString("username", name);
loginPrefsEditor.putString("password", pwd);
loginPrefsEditor.commit();
} else {
loginPrefsEditor.clear();
loginPrefsEditor.commit();
}
}
doSomething();
}
public void doSomething() {
.......
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言