【发布时间】:2014-02-23 15:33:55
【问题描述】:
我正在尝试从对话框提示中获取用户输入,以确定变量是真还是假。 我需要在执行 List Activity 类中的任何其他代码之前执行此操作。
问题是无论我在哪里调用显示提示的方法,类中的其余代码都会在对话框返回用户选择之前继续执行!
哪里是放置对话框提示和停止执行代码表单的最佳位置,直到我们通过对话框得到用户的响应?
谢谢 夏兰
PS 这是我在 ListActovty onCreate 方法中调用的代码:
private void previewDives() {
//ask user if they wish to preview images in ist view as will take more time
AlertDialog.Builder build = null;
AlertDialog dialog = null;
build = new AlertDialog.Builder(this);
build.setCancelable(true);
build.setMessage("Do you want to preview your Dive Site images? \nThis may take more time if you have a large number of dives");
build.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// preview dives
preiwImagesInListView= true;
value++;
//return;//exit
}// end on click
});// end pos button take photo
// get photo from SD card option
build.setNegativeButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
preiwImagesInListView=false;
value++;
//return;//exit to oncreate
}// end onclick
});// end pos button take photo
dialog = build.create();
dialog.setTitle("Preview Dive Images");
dialog.show();
//return preiwImagesInListView;
}
【问题讨论】: