Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-28 Thread YuviDroid
Oh well I gave it a shot :D

Anyway, glad you found the problem/solution at the end ;)


Cheers,
Yuvi

On Sat, Jan 28, 2012 at 7:22 AM, TreKing treking...@gmail.com wrote:

 On Fri, Jan 27, 2012 at 6:00 PM, YuviDroid yuvidr...@gmail.com wrote:

 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().


 Thanks. That didn't work (actually led to the default could not load
 widget error layout), but playing around with it a bit more I finally
 found the problem.

 As expected, I was missing something obvious: my linear_layout_entry
 layout that I have been inflating had its height set to match_parent ...
 So the first one was filling the parent and leaving no room for the rest
 ... I just couldn't tell due to the backgrounds being the same ...

 *face palm*

 Man I love posting to the group only to realize I'm being an idiot.

 Thanks for the help!



 -
 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

Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread Kostya Vasilyev
I don't see anything in the source for RemoteViews that would do that, 
maybe I'm not looking well enough.


My suggestion would be -- for debugging purposes only -- to simulate a 
RemoteViews update cycle within your own application, checking the 
result, and stepping through the code if necessary.


By this I mean: writing your views object into a Parcelable, cloning a 
new instance from that Parcelable, inflating your widget's root layout, 
and applying the cloned RemoteViews.


Oh, and one more thing: your widget updates are all executed from one 
place in the code, updating everything at once -- the views, the pending 
intents if any, the background images -- right?


-- Kostya

27.01.2012 8:37, TreKing ?:

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 http://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 


--
Kostya Vasilyev

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

Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread TreKing
On Fri, Jan 27, 2012 at 8:31 AM, Kostya Vasilyev kmans...@gmail.com wrote:

 I don't see anything in the source for RemoteViews that would do that,
 maybe I'm not looking well enough.


Yeah, I briefly stepped through the source and didn't see anything obvious.
But then my eyes glazed over =) I haven't had to spend much time with the
source so I thought I'd ask first before trudging through and trying to
make sense of it all.


 My suggestion would be -- for debugging purposes only -- to simulate a
 RemoteViews update cycle within your own application, checking the result,
 and stepping through the code if necessary.

 By this I mean: writing your views object into a Parcelable, cloning a
 new instance from that Parcelable, inflating your widget's root layout, and
 applying the cloned RemoteViews.


Good idea - I'll give that a shot this weekend. Gah, and this was going so
well :(


 Oh, and one more thing: your widget updates are all executed from one
 place in the code, updating everything at once -- the views, the pending
 intents if any, the background images -- right?


Well, I do update them in 3 places: onUpdate() to set up the widgets from
configured data when necessary; in the configuration Activity when I'm done
setting up the widget to initialize it; and then in this IntentService when
it's called on tapping the widget.

But this is the only place that updates the widget after it's been
configured and added to the home screen. And it works as expected if it's
not the same layout being added to the LinearLayout (whether it's in a loop
or sequentially) so I don't think my layout is being modified anywhere else.

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

Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread Mark Murphy
On Thu, Jan 26, 2012 at 11:37 PM, TreKing treking...@gmail.com wrote:
 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 ...

Try calling setId() on LinearLayout before passing it to addView(),
giving it a unique ID value, and see if that helps.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 4.0 Programming Books: http://commonsware.com/books

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


Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread TreKing
On Fri, Jan 27, 2012 at 9:44 AM, Mark Murphy mmur...@commonsware.comwrote:

 Try calling setId() on LinearLayout before passing it to addView(), giving
 it a unique ID value, and see if that helps.


Actually, I had that idea. I forget the exact message, but it yelled at me
that I can't call that particular method (via the setInt method of the
RemoteViews interface). It then displays a default error layout for the
widget.

-
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

Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread Kostya Vasilyev


27.01.2012 19:20, TreKing пишет:


Well, I do update them in 3 places: onUpdate() to set up the widgets 
from configured data when necessary; in the configuration Activity 
when I'm done setting up the widget to initialize it; and then in this 
IntentService when it's called on tapping the widget.


But this is the only place that updates the widget after it's been 
configured and added to the home screen. And it works as expected if 
it's not the same layout being added to the LinearLayout (whether it's 
in a loop or sequentially) so I don't think my layout is being 
modified anywhere else.




Ok.

Just remember - for a given widget instance, only one, the most recent 
RemoteViews survives.


--
Kostya Vasilyev

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


Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread YuviDroid
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

Re: [android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-27 Thread TreKing
On Fri, Jan 27, 2012 at 6:00 PM, YuviDroid yuvidr...@gmail.com wrote:

 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().


Thanks. That didn't work (actually led to the default could not load
widget error layout), but playing around with it a bit more I finally
found the problem.

As expected, I was missing something obvious: my linear_layout_entry
layout that I have been inflating had its height set to match_parent ...
So the first one was filling the parent and leaving no room for the rest
... I just couldn't tell due to the backgrounds being the same ...

*face palm*

Man I love posting to the group only to realize I'm being an idiot.

Thanks for the help!

-
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

[android-developers] Dynamically populating LinearLayout in an AppWidget

2012-01-26 Thread TreKing
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