我有如下情况:
我有一个方法,用于对用户输入进行一些检查。
该方法返回true或false。
现在,如果符合条件,我的方法会弹出一些对话框。
由于onClick返回void,我无法从onClick中返回Boolean。
请问是否有任何解决办法?
谢谢!
我有一个方法,用于对用户输入进行一些检查。
该方法返回true或false。
现在,如果符合条件,我的方法会弹出一些对话框。
由于onClick返回void,我无法从onClick中返回Boolean。
请问是否有任何解决办法?
谢谢!
public Boolean retrunvalue=false;
private Boolean performchecks() {
if (!reminderdatepicked && !remindertimepicked) {
AlertDialog.Builder builder = new AlertDialog.Builder(
NewGenericEvent.this);
builder.setTitle(R.string.remindernotsettitle);
builder.setMessage(R.string.remindernotmessage)
.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
retrunvalue= true;//NOT A GOOD IDEA
//BECAUSE IT RETURNS TRUE
//ONLY WHEN performchecks()
//IS CALLED THE SECOND TIME
}
});
builder.setNegativeButton(R.string.no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
retrunvalue= false;
}
});
builder.create().show();
return retrunvalue;
}
return true;
}
true
可能性,而不是在第二次调用performchecks()
时才返回。 - Lisa Anne