当我点击登录按钮时给予用户名和密码意味着登录将成功。 当我点击用户名和密码复选框后,如果我成功登录后,我现在关闭应用程序,如果我再次打开应用程序的用户名和密码必须是他们在文本框中。现在我直接点击登录按钮,它必须完全登录成功。如何在Android登录页面中使用共享偏好概念android
我试试这个代码
public class Login extends Activity {
CheckBox check;
private static final String UPDATE_URL = "http://202.62.91.45/NewCozyDine/login1.php3";
public ProgressDialog progressDialog;
private EditText UserEditText;
private EditText PassEditText;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Please wait...");
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
UserEditText = (EditText) findViewById(R.id.username);
PassEditText = (EditText) findViewById(R.id.password);
check=(CheckBox) findViewById(R.id.checkbox);
Button button = (Button) findViewById(R.id.okbutton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int usersize = UserEditText.getText().length();
int passsize = PassEditText.getText().length();
if(usersize > 0 && passsize > 0) {
progressDialog.show();
String user = UserEditText.getText().toString();
String pass = PassEditText.getText().toString();
doLogin(user, pass);
} else createDialog("Error","Please enter Username and Password");
}
});
我写为XML解析器(从服务器数据库验证)登录按钮。如何写了复选框记得
看看http://developer.android.com/reference/android/content/SharedPreferences.html。使用SharedPreferences存储您的凭证和复选框状态,并在下次调用时检索。 – Rajesh 2012-04-19 12:43:34