我是 java 的新手,需要一些帮助。我想在此注册页面中添加一个功能,用户不能将密码和用户名字段留空。如果您能键入代码行,我将不胜感激,因为它对我来说更容易形象化。
我已经尝试在这个页面上实现 else if 但它不起作用并且也没有错误,所以我删除了那些代码。这些代码没有出现在我在这里显示的代码行中。干杯
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
db = new DatabaseHelper(this);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mTextCnfPassword = (EditText)findViewById(R.id.edittext_cnf_password);
mButtonRegister = (ImageButton)findViewById(R.id.imagebutton_register);
mTextViewLogin = (TextView)findViewById(R.id.textview_login);
mTextViewLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent LoginIntent = new Intent(RegisterActivity.this,LoginPageActivity.class);
startActivity(LoginIntent);
}
});
mButtonRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = mTextUsername.getText().toString().trim();
String pwd = mTextPassword.getText().toString().trim();
String cnf_pwd = mTextCnfPassword.getText().toString().trim();
if(pwd.equals(cnf_pwd)) {
Long val = db.adduser(user,pwd);
if(val > 0){
Toast.makeText(RegisterActivity.this,"Successfully Registered.",Toast.LENGTH_SHORT).show();
Intent movetoLogin = new Intent(RegisterActivity.this,LoginPageActivity.class);
startActivity(movetoLogin);
}
else{
Toast.makeText(RegisterActivity.this,"Registration Error.",Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(RegisterActivity.this,"Those passwords didn't match.Try Again.",Toast.LENGTH_SHORT).show();
}
}
});
}
}
慕丝7291255
互换的青春
尚方宝剑之说
相关分类