【发布时间】:2017-01-12 15:12:09
【问题描述】:
在给定的代码中,我的所有 if 都正常工作,但我正在检查 cp1.equals(p1) 是否不工作。甚至 Toast 也没有出现。所以,我尝试评论数据库管理部分,然后 toast 工作。我是安卓新手。请帮忙。我真的不能理解我的错误。
public void onClick(View view) {
EditText u = (EditText) findViewById(R.id.username1);
EditText p = (EditText) findViewById(R.id.password1);
EditText cp = (EditText) findViewById(R.id.cpassword);
EditText id=(EditText)findViewById(R.id.id);
String u1=u.getText().toString();
String p1=p.getText().toString();
String e=id.getText().toString();
String cp1=cp.getText().toString();
if ((u1.equals("")) || (p1.equals("")) || cp1.equals("")||e.equals("")) {
Toast.makeText(this, "No field can be left empty!!", Toast.LENGTH_LONG).show();
}
if(cp1.equals(p1)){
Toast.makeText(this,"check",Toast.LENGTH_SHORT).show();
dbHelper = new DBHelper(this);
newDB=dbHelper.getWritableDatabase();
newDB.execSQL("INSERT INTO "+tablename+" VALUES ('"+u1+"', '"+p1+"', '"+e+"' );");
Toast.makeText(this,"SUCCESSFULLY REGISTERED!",Toast.LENGTH_SHORT).show();
Intent i = new Intent(register1.this,MainActivity.class);
startActivity(i);
}
if (cp1.equals(p1)==false)
{
Toast.makeText(this,"Confirm PAssword and password fields should be equal",Toast.LENGTH_SHORT).show();
}
}
}
【问题讨论】:
-
尝试写
if (!cp1.equals(p1))而不是if (cp1.equals(p1)==false),看看toast是否出现。 -
尝试 cp1.equalsIgnoreCase(p1) 而不是 cp1.equals(p1)。
标签: java android android-studio if-statement