我希望这是一个简单的解决方法。我无法弄清楚我在这里缺少什么。这是一个登录表单,我让它记住了以前带有共享首选项的登录电子邮件。editText 框在 onCreate 中预填充了电子邮件,但 onClick 认为 editText 字段为空。有任何想法吗?
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
setContentView(R.layout.main);
email = (EditText) findViewById(R.id.login_email_address);
pass = (EditText) findViewById(R.id.password);
login = (Button) findViewById(R.id.blogin);
text = (TextView) findViewById(R.id.invalid_email);
// register listeners
newuser.setOnClickListener(this);
login.setOnClickListener(this);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
String restoredemail = app_preferences.getString("username", null);
if (restoredemail != null) {
email.setText(restoredemail);
email.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if (email.getText().toString()
.matches("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+")
&& s.length() > 0) {
text.setText("valid email");
valid_email = true;
//user_email = email.toString();
} else {
text.setText("invalid email");
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.blogin:
if (valid_email == true) {
new AttemptLogin().execute();
}else{