首页 > 代码库 > android - asynTask中打开多选alertDialog

android - asynTask中打开多选alertDialog

private class xxxAsyncTask extends AsyncTask<String, Void, Boolean> {
	...
        AlertDialog.Builder alertBuilder ;
	...
        @Override
        protected void onPreExecute() {
	...
            alertBuilder = new AlertDialog.Builder(ResultActivity.this);
	...
        }


        @Override
        protected Boolean doInBackground(String... params) {
            ...
        }


        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);


                            alertBuilder.setTitle("Choose Attraction");
			    ... //prepare data
                            String[] arr = new String[operationNames.size()];
                            operationNames.toArray(arr);
                            alertBuilder.setItems(arr, new DialogInterface.OnClickListener() {


                                @Override
                                public void onClick(DialogInterface dialog, int index) {
                                    try{
					// if select index == x , do something 
					
                                        //// keep in mind that java is not allowed to block the UI thread doing network post
                                        //// have to wrap this inside one async task, e.g:
                                        new xxxAsync().execute(usageUrl, json);
					...
                                    }
                                    catch (Exception ex){


                                    }
                                    finally {
                                        dialog.dismiss();
                                    }
                                }
                            });
                            alertBuilder.create().show();
                      
        }
    }


android - asynTask中打开多选alertDialog