Android: displaying a preview of widget in my own app

Viewed 21

I'm creating an App that has a homescreen widget, and I'd like to have it so the user can see a live preview of what the widget will look like, within my actual App activity, when they're configuring settings for the widget. I recently downloaded an app that did that exact thing, and it seemed like a great feature.

Any idea how I'd go about accomplishing this? I found some references to AppWidgetHostView, is that what I need?

I'm very new to Android development (as in just started the tutorials today), so bear with me if this question is missing anything important!

1 Answers

I found some references to AppWidgetHostView, is that what I need?

AppWidgetHostView is one option. I think you can put that in your layout and call updateAppWidget() on it, supplying your RemoteViews.

Or, your activity/fragment can call apply() on the RemoteViews to have that UI poured into some ViewGroup (e.g., a FrameLayout).

In either case, you would need your function that creates your RemoteViews to be available to both your AppWidgetProvider and your activity/fragment that implements your preview.

Related