当我按下按钮将我重定向到页面时,当它显示消息时,我会尝试,但它不起作用。成功后,会显示消息,但不会转发给我。
private void registerUser() {
try {
Account account = new Account();
account.setpAddress(edt_adress.getText().toString());
account.setpBloodGroup(edt_blood.getSelectedItem().toString());
account.setpFirstName(edt_first.getText().toString());
account.setpMidName(edt_mid.getText().toString());
account.setpFamilyName(edt_fam.getText().toString());
account.setpGender(edt_gender.getSelectedItem().toString());
account.setpPhone(edt_phone.getText().toString());
account.setpEgn(edt_egn.getText().toString());
account.setuPassword(edt_password.getText().toString());
account.setuUsername(edt_username.getText().toString());
INodeJS accountservice = RetrofitClient.getInstance().create(INodeJS.class);
Call call = accountservice.create(account);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
Account result = (Account) response.body();
Toast.makeText(getApplicationContext(), result.getNotes(), Toast.LENGTH_LONG).show();
if (result.getNotes().equals("Success")) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
// startActivity(intent);
}
@Override
public void onFailure(Call call, Throwable t) {
Toast.makeText(getApplicationContext(), getString(R.string.createfield), Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
看起来result.getNotes().equals("Success")
不是真的,你认为它应该是真的吗?CCD_ 2是区分大小写的;成功;不等于";成功;以及";成功注意空白
也许你可以试试这个说法:
result.getNotes().toLowerCase(Locale.getDefault()).trim().equals("success")
toLowerCase
将使您的所有字母都成为小帽,trim
将删除String
开始和结束时的所有空白
还有equalsIgnoreCase
方法,所以它可能也如下所示:
result.getNotes().trim().equalsIgnoreCase("success")