我正在调用函数validate()
如果条件为真,它应该进入return
并保持在该页面上,但是当我调试时即使条件为真,它也不会返回。任何人都可以帮助我。我已经尝试了很多,并决定发布。请帮忙
if(balance>0) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(DetailActivity.this);
alertDialog.setTitle("Confirmation");
alertDialog.setMessage("Order has been removed successfully.\n\nRepayable Amount is Rs " + balance);
final LinearLayout diagLayout = new LinearLayout(OrderDetailsActivity.this);
diagLayout.setOrientation(LinearLayout.VERTICAL);
final EditText text = new EditText(OrderDetailsActivity.this);
text.setPadding(10, 10, 10, 10);
text.setHint("User Pin");
text.setGravity(Gravity.CENTER);
text.setTextSize(20);
diagLayout.addView(text);
alertDialog.setView(diagLayout);
alertDialog.setPositiveButton("REFUND", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
validate(text);
Intent intent = new Intent(getApplicationContext(), ScreenActivity.class);
startActivity(intent);
}
});
alertDialog.setNegativeButton("TO ACCOUNT", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
removeOrder();
dialog.cancel();
}
});
alertDialog.show();
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(OrderDetailsActivity.this);
builder.setMessage("Order has been removed successfully")
.setTitle("Removed");
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
hideProgressWheel(true);
}
}
@Override
public void onErrorResponse(RPCRequest request, ResponseError error) {
showAlert(error.getErrorSummary(), error.getErrorTitle());
hideProgressWheel(true);
}
};
private void validate(EditText text) {
String pin = text.getText().toString();
if (pin == null || pin.isEmpty()) {
showToast("enter user pin");
return;
}
}
答案 0 :(得分:0)
如果我找到你的话,你将从validate()
方法返回,而不是从正回调中返回。
答案 1 :(得分:0)
只返回布尔值,否则不会在void中使用return,因为它只会从validate中返回而不是从你调用的地方返回
private boolean validate(EditText text) {
String pin = text.getText().toString();
if (pin == null || pin.isEmpty()) {
showToast("enter user pin");
return false;
}
return true;
}
并在调用网站检查这样
if(!validate(text)) return;
然后它不会再进一步了。