我正在使用专用库处理图像。在出现警告对话框然后单击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);
,但它也没有用。有人有想法吗?
答案 0 :(得分:3)
试试这个:
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();