Search code examples
androidandroid-appwidgetviewstub

Android appwidget ViewStub


I am trying to develop a rather complicated appwidget which could change part of it programmatically. Android suggests for such things to use ViewStub widget.

According to AppWidgets page RemoteViews supports ViewStub.

Because when working with RemoteViews I can't findViewById(). So I've tried using

RemoteViews.setViewVisibility(viewstub_id, View.VISIBLE)

and that works on devices with API > 15.

The problem is, that it doesn't work on older APIs and crashes when inflating layout.

Error inflating AppWidgetppWidgetProviderInfo(provider=ComponentInfo{com.example.app/com.example.app.widgetProvider}): android.view.InflateException: 
Binary XML file line #56: Error inflating class android.view.ViewStub

I've tried to look for any mention about API compatibility, but ViewStub should be available from API 1.

So is there any information about that when we can use ViewStub in appwidget?

Thanks!


Solution

  • I found a mention about that ViewStub can be in RemoteViews only from API 16.

    Quite buried information though.