Folks,
I'm getting my feet wet on app widgets so I'm probably missing something
obvious, but I've hit a snag that's got me stumped.
Basically, I cannot seem to dynamically add more than one instance of the
same layout to a LinearLayout living in a RemoteViews object. Only the *
first* item gets added.
Has anyone seen anything like that?
Here's more detail to clarify: I've got something like this in an
IntentService that creates a list of objects to display.
// Create remote view for main widget layout
RemoteViews views = new RemoteViews(getPackageName(),
R.layout.widget_layout);
// "list" is some list of objects populated in the IntentService
for (int i = 0; i < list.size(); i++)
{
// Create remote view for the object to add to linear layout
RemoteViews v = new RemoteViews(getPackageName(),
R.layout.linear_layout_entry);
// ... Set Text on text views in "v" for the current object
// Add new view to the linear layout in the widget
views.addView(R.id.ll_widget, v);
}
AppWidgetManager man = AppWidgetManager.getInstance(this);
man.updateAppWidget(widgetID, views);
Now, this works as expected for the first item in the list. However, all
others seem to be getting ignored - my widget only shows the first entry in
the list even though there is plenty of room.
I've stepped through the loop and it's definitely getting populated and I
can see that the main "views" RemoteViews object has multiple "nested
views" that should be my dynamic views, but they just don't appear.
If I manually add instances of the layout (the one I'm inflating) to the
linear layout via the designer, they show up.
If I dynamically add instances of *different* layouts to the LinearLayout
one after the other, they show up.
If I dynamically add instances of *the same layout* to the LinearLayout,
then only the first shows up.
So apparently I can only add one instance of a given layout to a
LinearLayout for a widget? That does not seem right at all ...
I've gone though the docs and samples and searched this list,
StackOverflow, and b.android.com and not found anything about this.
There are no warnings or errors in the LogCat. I've tried on my 2.3.3
device and various emulators and no dice.
I can hack this up and manually add a bunch of the layouts and not use the
ones I don't need, but I really feel like this should work.
Anyone else seen this while working on widgets and have a clue what I'm
doing wrong?
Thanks.
-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en