Hey,

I think I had a similar problem some time ago...unfortunately I don't
remember exactly how I solved. However I think I used
RemoteViews.removeAllViews().

I would try:
RemoteViews views = new RemoteViews(getPackageName(),
R.layout.widget_layout);
views.removeAllViews(R.id.ll_widget);

... rest of your code.


Hope it helps!
Yuvi

http://www.droidahead.com

On Fri, Jan 27, 2012 at 5:37 AM, TreKing <treking...@gmail.com> wrote:

> 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 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




-- 
YuviDroid
Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget
to quickly access your favorite apps and contacts!)
http://android.yuvalsharon.net

-- 
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