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?
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.
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.
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.
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.
An even simpler idea, is to put the progress bar inside some container (say a linear layout) and show/hide the container.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With