7

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?

Justin
  • 6,564
  • 6
  • 37
  • 34

2 Answers2

17

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

Aviv Reznik
  • 186
  • 1
  • 2
12

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the info and the workaround! Just as an FYI, I am currently compiling against the 1.5 SDK so it may have been fixed in a later version. – Justin Mar 10 '10 at 14:43
  • Probably not, since I was looking at more current code (via Google Code Search) when writing the answer. – CommonsWare Mar 10 '10 at 15:33
  • It is still not working from API Level 8 on. But the tip to use an additional layout is working :) – Markus Rudel Apr 30 '12 at 07:21