Hi Juan, This is pretty easy to do.
One way is to implement a class in your UI class that extends AsyncTask. Then you can instantiate the ProgressDialog class (which you may want to extend for various reasons) in the constructor. In the doInBackground method call publishProgress which will call across the thread boundary to onProgressUpdate (for which your sub class provides an implementation). onProgressUpdate interacts directly with the ProgressDialog (if you tried to do that from doInBackground it will throw an exception). By subclassing ProgressDialog you can arrange to change the text and style of the progress bar (determinate/imdeterminate) and other characteristics as you want to show progress. You can pass all kinds of useful progress information through publishProgress which onProgressUpdate can interpret. Another neat trick is to implement a Toast in onPostExecute showing the result of the async operation, if that would be useful to the user (like maybe success or failure). Hope this helps. On Aug 30, 1:58 am, "Juan David Trujillo C." <[email protected]> wrote: > Hi all! > > I am creating an app that show a Progress dialog in AsyncTask to > inform the user while web information is being fetched. I've read > there are two ways of doing this: Using handlers or creating and > executing an inner class that overrides the AsyncTask class > > I am trying to create and executing inner class that overrides the > AsyncTask class, which runs a resource-intensive thread in the > background, to provide progress updates, and reports back when > finished. > > On the OnCreate, I have: > protected Dialog onCreateDialog(int id) { > return ProgressDialog.show(ListSituation.this, "", "Loading. > Please wait...", true); > > } > > throws the following error: > android.util.AndroidRuntimeException: requestFeature() must be called > before adding content > > On the other hand, if I do it this way: > protected Dialog onCreateDialog(int id) { > return progressDialog(); > > } > > public Dialog progressDialog(){ > Log.d("Tifersons", "****************************Entra a > progressDialog.."); > ProgressDialog dialog = new ProgressDialog(this); > dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); > dialog.setMessage("Loading..."); > dialog.setIndeterminate(true); > dialog.setCancelable(false); > return dialog; > > } > > No dialog gets shown. > > This is being done inside an activity included in a Tab. When I > switch to another Activity in the tab, the progressDialog gets shown. > > Thanks for your help, > > Best regards, > > Juan. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

