我希望单次显示不成功的消息,但每次都打印..
for (String[] s : array) {
if (s[0].equals(edtUsername.getText().toString()) && s[1].equals(edtPassword.getText().toString())) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
return;
} else {
Toast.makeText(getApplicationContext(), "UnSuccess", Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:2)
如果您只想查看UnSuccess
吐司留言一次,则必须将其放在for-loof
之外,如下所示...
for (String[] s : array) {
if (s[0].equals(edtUsername.getText().toString())
&& s[1].equals(edtPassword.getText().toString())) {
Toast.makeText(getApplicationContext(), "Success",
Toast.LENGTH_LONG).show();
return;
}
}
Toast.makeText(getApplicationContext(), "UnSuccess",
Toast.LENGTH_LONG).show();