我希望有人能帮帮忙!我对 android 还很陌生,并且遇到了文本字段的问题。我有 3 个文本字段要求用户输入信息,当单击注册按钮时,一条消息将让用户知道他们已注册并将他们重定向到登录活动。我的问题是我想检查用户是否已完成所有 3 个文本字段,如果没有显示错误消息并允许他们重试。我可以显示错误消息,但即使如果单击 reg 按钮,所有文本字段都不完整,它仍然会告诉用户他们已注册并将用户重定向到登录活动,如果有人能告诉我我出错了,我已经发布了我的代码, 提前致谢!
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String data1 = inputName.getText().toString();
if(data1.trim().equals("")){
Toast.makeText(RegisterActivity.this, "Please enter your name",
Toast.LENGTH_SHORT).show();
}
String data2 = inputEmail.getText().toString();
if(data2.trim().equals("")){
Toast.makeText(RegisterActivity.this, "please enter email address",
Toast.LENGTH_SHORT).show();
}
String data3 = inputPassword.getText().toString();
if(data3.trim().equals("")){
Toast.makeText(RegisterActivity.this, "Please enter a password",
Toast.LENGTH_SHORT).show();
}
if(data1 != null && data2 != null && data3!= null){
mySQLiteAdapter.insert(data1, data2, data3);
updateList();
Toast.makeText(RegisterActivity.this, "You are now registered",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
inputName.setText("");
inputEmail.setText("");
inputPassword.setText("");
}
else Toast.makeText(RegisterActivity.this, "Error please try again!",
Toast.LENGTH_SHORT).show();
}
};