I want to extend the little widget I created a bit more by adding a preview of the widget while you are configuring it. While I could easily do this by just creating a preview that looks like the widget in the configuration activity - I was wondering if there was a way to actually imbed a real widget into an activity - and change that widget using remote views while inside the activity without changing the real widget until the "done" button has been pressed.
I've seen a few widgets on the market doing this and I was wondering if they had either, just recreated the widget using views inside the activity or, were the actually imbedding their widget inside the configuration activity?
Thanks, any help is appreciated.
(By the way, I don't think the "Widget Preview" feature in android 3.0 and ^ is what I am wanting here)
Widgets work with the real-time website data and can be personalized to respond to website identity. Some of the most popular examples of widgets are event countdowns, website visitors counter, clocks, daily weather report, etc.
I know I'm a little late, but I ran into the same problem and found a solution.
What you need is the apply method from the RemoteViews class. You need to pass the context and parent view to it, and it will return an inflated widget view that you have to attach to the hierarchy.
For example:
val remoteViews = RemoteViews(context.packageName, R.layout.widget)
val widgetView = remoteViews.apply(context, parentView)
parentView.addView(widgetView)
It is also then possible to reapply remote views instead of completely recreating the hierarchy:
remoteViews.reapply(context, widgetView)
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