0

I have a progress dialog in my AsyncTask extended class. I have set the layout to the progress dialog using setcontentview(). I want to change the design of the progress dialog and show for 2 seconds when it is complete (i.e. in PostExecute()).

I start Progress dialog in onPreexecute() and dismiss it in onPostexecute() methods.

This is how I initialised progress dialog in onPreexecute

progressDialog = ProgressDialog.show(context, null, null);
progressDialog.setContentView(R.layout.progress_meditate);
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
progressDialog.setProgressDrawable(new ColorDrawable(Color.WHITE));

I tried below code in onPostExecute

progressDialog.setContentView(R.layout.progress_complete);
sleep(2000);
progressDialog.dismiss();

but it is not working. My progress_complete layout is not getting shown. Progress dialog gets dismissed after sleep time with same design.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
hiranes
  • 17
  • 10

4 Answers4

0

01. First step initialize the progressBar and ProgressBarText

 private ProgressBar progressBar;
 private TextView progressBarText;

02. The second step declare this OnCreate Method

  progressBar.setVisibility(View.VISIBLE);
  progressBarText.setVisibility(View.VISIBLE);

03. The third step declare this onPostExecute Method

  progressBar.setVisibility(View.GONE);
  progressBarText.setVisibility(View.GONE);

That's it. I think it's is help for you.

Masum
  • 1,037
  • 15
  • 32
  • What I want to achieve is change the design of the progress bar. When progress is finished the progress bar should change to another layout – hiranes Jan 19 '19 at 11:53
  • You targeted layout call after progress bar loading finished. – Masum Jan 19 '19 at 12:02
  • that is a different layout. after finish I want to change the colour,message,picture etc on the layout and show for 2 seconds before progress dialog is dismissed. – hiranes Jan 19 '19 at 12:08
0

For this you can not change the design on runtime. the only possible way of showing a dialog with different design on post execute is that create a new dialog and dismiss the previous one and show the new one.

Khurram Shahzad
  • 162
  • 2
  • 12
0

The less simple solution would be to extend or creating your own ProgressDialog. On the other hand in the Android documentation you can find the following:

Caution: Android includes another dialog class called ProgressDialog that shows a dialog with a progress bar. This widget is deprecated because it prevents users from interacting with the app while progress is being displayed. If you need to indicate loading or indeterminate progress, you should follow the design guidelines for Progress & Activity and use a ProgressBar in your layout, instead of using ProgressDialog.

I Would suggest/recommend to shift to ProgressBar as the starting point of the solution but it is your call.

I think it would be more easy to solve your issue because ProgressBar is just another view that can be overlap on finish.

dogood
  • 331
  • 2
  • 5
  • The issue is that I don't want the user to do anything while this progress is being shown. :-) Thats why I chose progress dialog. – hiranes Jan 21 '19 at 05:11
  • I understand what you are trying to achieve but why to develop a new solution with a deprecated component? Check the following link to a suggested solution: https://stackoverflow.com/a/45613741/985266 – dogood Jan 21 '19 at 12:21
0

Then create two progress dialog, one above another, dismiss one first and another one after 2 seconds. It will work

Android Killer
  • 18,174
  • 13
  • 67
  • 90