我有一个列表视图,其中包含复选框.对于每个复选框(它们大约为3),它具有特定的AsyncTask.
我永远不知道用户选择什么样的复选框,所以我不能将异步任务放在AlertDialog的末尾,因为我永远不知道用户是否只选择了一个复选框,或者两个或三个.
因为AsyncTask是按步骤执行的(仅当第一个Async完成时才是第二个开始),我想到了一个新的AsyncTask与AlertDialog的结尾.
private class showMessageAsync extends AsyncTask<Void, Integer, String> {
@Override
protected String doInBackground(Void... params){
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(getApplicationContext).create();
alertDialog.setTitle("The Process");
alertDialog.setIcon(R.drawable.success);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setMessage("All done!");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent A = new Intent(DownloadActivity.this, Menu_activity.class);
startActivity(A);
finish();
}
});
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Intent A = new Intent(DownloadActivity.this, Menu_activity.class);
startActivity(A);
finish();
}
});
alertDialog.show();
return "Executed";
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
10-21 04:24:34.117: E/AndroidRuntime(1026): FATAL …Run Code Online (Sandbox Code Playgroud) android ×1