android 加载程序未显示在对话框中

android loader not showing in dialog box

我正在使用专用库处理图像。这发生在显示警告对话框之后,然后当单击 positive/ok 时图像被处理。这个处理过程可能很长,所以我尝试显示一些加载程序。所以我尝试了这个:

setPositiveButton(getResources().getString(...), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Activity activity = getActivity();
                        ProgressDialog pd = ProgressDialog.show(activity, "Process", "Searching...", true, false);
                        ImageView image = (ImageView) activity.findViewById(...);

                        try {
                            process_image
                        } catch (Exception e) {
                            //some thing
                        }
                        // some code
                        pd.dismiss();

但加载程序未显示。我也试过 activity.findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE); 也没有用。有人有想法吗?

试试这个:

class proceesImageTask extends AsyncTask<Void,Void,Void>
{
 ProgressDialog dialog;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();

                dialog = ProgressDialog.show(context, "","Please wait...", true);
                dialog.show();

            }
@Override
            protected Void doInBackground(String... str) {
//your process
}

@Override
            protected void onPostExecute(Void result) {
dialog.dismiss();   
}
}

new proceesImageTask().execute();