mlykotom
mlykotom

Reputation: 5155

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!

Upvotes: 4

Views: 649

Answers (2)

ampedNinja
ampedNinja

Reputation: 31

Very old question but one thing you can also do is, if your app widget is somewhat modular. Add additional views inside of others using addView. One thing to be careful of is, you will near to clear all remoteviews for that particular module in between updates or you will ended up with repeated adds.

Upvotes: 0

mlykotom
mlykotom

Reputation: 5155

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

Quite buried information though.

Upvotes: 1

Related Questions