I am processing an image with a dedicated library. This happens after an alert dialog box is showed up and then when positive/ok
is clicked the image is processed. This processing can be long so I try to show up some loader. So I tried this :
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();
but the loader is not showing. I also tried with activity.findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
and it didn't work either. Someone has an idea ?
Try This:
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();