Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting RemoteView into a View

I am trying to render a RemoteViews instance onto a Canvas, like I do with a regular View. I use

RemoteViews.apply(context, null)

and it returns a FrameLayout with all the views nested and properly measured (location and size is correct,) but after using .draw on the returned view, it renders all elements with no values -- TextViews are empty, AnalogClock is reset at 00:00 and so on.

Any ideas? I'm lost :(

like image 463
gilm Avatar asked Jul 03 '13 09:07

gilm


1 Answers

Not sure if the question is still actual. Nevertheless here is my experience with RemoveViews. It appears you cannot just call draw() on the returned view. You have to add this view to a parent container to make it a part of global view hierarchy. For instance, you have an Activity with a single FrameLayout in it. Your code will look like this.

FrameLayout parent = findViewById(R.id.container);
View view = RemoteViews.apply(getActivity(), parent);
parent.addView(view);

Now you should be able to see tests. If you set listeners, they will work properly too.

like image 175
sergej shafarenka Avatar answered Nov 14 '22 10:11

sergej shafarenka