android - asynTask中打开多选alertDialog

Posted _iorilan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

在 AsynTask (Android Studio) 中获取 EOFException [重复]

Android开发之AsynTask的使用

android中带有Endless Listview Scroll的AsynTask

带有进度对话框取消的 Android AsyncTask

Android Kotlin 多选下拉菜单

通过AsyncTask访问后台后得到的返回数据在Android端显示