Widget /RemoteView question.

I have one widget definition (AppWidgetProvider) in my project.

I assume that even with one single definition, I can have different
instances of the same widget class and the same widget layout
definition.

Now, I would like to be able to install the same widget several times
on the screen at the same time, to have different instances of it, and
every time when the user click one of these widgets on the screen , to
launch an activity and to pass the corresponding widget id to the
activity.

Example : when the first widget is created and widgetId is 1  (for
example), when the user press the widget, to see "calling widget id =
1" on the Activity screen. When the second widget is created and
widgetid is 2 for example, when the user press widget #2, to see
"calling widget id = 2" on the activity screen. If he press the first
widget again, should see "calling widget id = 1" on the Activity
screen

in onUpdate(), the very first time when the widget is created, I get
the widgetID, then I set OnClickListener and I put the widgetId in the
extras :

RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
widgetLayout);

Intent startIntent = new Intent(context, TestActivity.class);
                startIntent.setAction(START_ACTIVITY);
                startIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 
widgetId);
                PendingIntent pendingIntent = 
PendingIntent.getActivity(context, 0,
startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                remoteViews.setOnClickPendingIntent(R.id.last_image, 
pendingIntent);

appWidgetManager.updateAppWidget(localAppWidgetIds, remoteViews);

I expect that every time, when the widget instance is created and I
execute
remoteViews = new RemoteViews(context.getPackageName(),
widgetLayout);

,a new layout instance to be be inflated/created  and remoteView will
have the (new) corresponding layoutId.

However, this is not the case, remoteView every time has the very same
layoutId after execution of
 remoteViews = new RemoteViews(context.getPackageName(),
widgetLayout);

So when I apply the remoteViews.setOnClickPendingIntent, it overwrites
the previous OnClickPendingIntent and widgetId is always the last one.


What happens in the example : when user creates widget 1, press it,
see "calling widget  1". When he creates widget 2 and presses it, he
will see "calling widget 2", but if he press widget 1 again, he will
see "calling widget 2" instead "calling widget 1".

Does anybody knows how I can obtain a separate instance of inflated
layout for the same widget instance to RemoteView, with one widget
definition?
 Then I'll be able to apply the listener (or other changes) only to
the same layout instance created together with the same widget
instance.

P.S. I would like to do that, without using the Honeycomb API.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to