Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgressBar in an AppWidget

I ran into an interesting situation with using a ProgressBar in an App Widget... The documentation (http://developer.android.com/guide/topics/appwidgets/index.html) says that ProgressBar is a supported widget class...

I have no problem getting the ProgressBar to display in my App Widget but the problem is that I want it to only be displayed as visual feedback to the user when background processing is happening.

On ImageViews I do this via RemoteViews.setViewVisibility() and everything works fine. However, with ProgressBar I get an exception saying that ProgressBar can't use this method.

Is this intentional or is this a bug? Is there any way to workaround this problem?

like image 632
Justin Avatar asked Mar 10 '10 09:03

Justin


People also ask

What is meant by ProgressBar describe with example?

We can display the android progress bar dialog box to display the status of work being done e.g. downloading file, analyzing status of work etc. In this example, we are displaying the progress dialog for dummy file download operation. Here we are using android. app. ProgressDialog class to show the progress bar.

What is ProgressBar indeterminate?

Indeterminate ProgressBars are a useful tool for communicating to our users that an operation is in progress when we cannot predict how long it is likely to take.

How do you set up a progress bar?

You can update the percentage of progress displayed by using the setProgress(int) method, or by calling incrementProgressBy(int) to increase the current progress completed by a specified amount. By default, the progress bar is full when the progress value reaches 100.

How do I change the progress bar icon on Android?

Go to the activity_main. xml file and refer to the following code. Open the activity_main. xml file and in the ProgressBar tag and set the drawable in indeterminateDrawable attribute.


2 Answers

An even simpler idea, is to put the progress bar inside some container (say a linear layout) and show/hide the container.

like image 123
Aviv Reznik Avatar answered Sep 23 '22 05:09

Aviv Reznik


It might be a bug. There's a particular annotation (@RemotableViewMethod) you need in the Java source code of Android itself to mark a method as being available via RemoteViews. View has this for setVisibility(), but ProgressBar overrides that method and does not have the annotation on its own edition. If @RemotableViewMethod is not inherited, and the override "undoes" the annotation, that would explain the symptom you see.

A workaround is to use two app widget layouts and choose the one you want (with or without ProgressBar) when you create your RemoteViews object when updating your app widget.

I'll make a note to try to replicate this and, if I see the same thing, I'll post an issue on it on the Android issue tracker.

like image 36
CommonsWare Avatar answered Sep 24 '22 05:09

CommonsWare