When I print out the before/after times around the 3 statements, it
takes 1 second.
Log.v(TAG, new java.util.Date().toString());


VERBOSE/BEFORE(768): Fri Apr 04 12:35:23 GMT 2008
VERBOSE/AFTER(768): Fri Apr 04 12:35:24 GMT 2008

However it takes 3.5 seconds to see the button in the layout. So the
delay is mainly in displaying it. Calling layout.invalidate() didn't
make a difference.

No, it is a small image: 863 bytes
The second time, I have already removed it from the layout, and am
calling getImageResource again, so I am surprised it is much quicker.
thanks,
Anil

On Apr 4, 1:33 am, hackbod <[EMAIL PROTECTED]> wrote:
> The most likely reason for it to be slow is that it is a huge image
> you are loading.  You could also try making it a PNG -- since pretty
> much all of the UI is PNG images, those are loaded into each app as
> they start, so the performance of that is clearly acceptable -- though
> as far as I know JPEG loading is quite reasonable as well.
>
> As for it taking less time the second time, well the resource is
> already loaded from the first time so it won't load it again.
>
> On Apr 3, 6:53 pm, Anil <[EMAIL PROTECTED]> wrote:
>
> > Any way to speed it up? for example if there is a way that the image
> > can be read in and stored in an image/icon class and if buttons can
> > share that image/icon. Also do you have any idea why it is quicker on
> > subsequent adds?
>
> > On Apr 3, 8:29 pm, "Romain Guy" <[EMAIL PROTECTED]> wrote:
>
> > > It looks like its setImageResource() which is taking a lot of time.
>
> > > On Thu, Apr 3, 2008 at 6:28 PM, Anil <[EMAIL PROTECTED]> wrote:
>
> > > >  When user clicks a button, these 3 lines are executed:
>
> > > >  button = new ImageButton(context);
> > > >  button .setImageResource(R.drawable.buttonJPG);
> > > >  layout.addView(button, new
> > > >  LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
> > > >  LayoutParams.WRAP_CONTENT));
>
> > > >  I observe that during the first add, it takes about 3.5 seconds.
> > > >  Subsequent adds are much quicker at about 0.5 sec.
> > > >  On actual devices, it will be many times slower.
> > > >  thanks,
> > > >  Anil
>
> > > >  On Apr 3, 6:29 pm, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> > > >  > I highly doubt this number since during a scroll, ListView basically
> > > >  > adds and removes Views all the time. It certainly doesn't take 3
> > > >  > seconds. There must be a bottleneck somewhere in your application.
>
> > > >  > On Thu, Apr 3, 2008 at 2:50 PM, Anil <[EMAIL PROTECTED]> wrote:
>
> > > >  > >  I have to say this - adding a button dynamically to a layout is
> > > >  > >  *extremely* slow.
> > > >  > >  It takes about 3 seconds for the button to be added!
>
> > > >  > >  On Apr 3, 3:40 pm, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> > > >  > >  > Hi,
>
> > > >  > >  > You cannot do this. If you try to put the same View in different
> > > >  > >  > layouts, an exception will be thrown anyway.
>
> > > >  > >  > On Thu, Apr 3, 2008 at 1:34 PM, Anil <[EMAIL PROTECTED]> wrote:
>
> > > >  > >  > >  I need to use the same buttons in several list items - each 
> > > > of which
> > > >  > >  > >  is a nested layout.
> > > >  > >  > >  Instead of creating a new button each time, to save time and 
> > > > space, I
> > > >  > >  > >  am going to reuse the same button, adding it to each layout. 
> > > > Of
> > > >  > >  > >  course, each OnClickListener will have to figure out which 
> > > > list item
> > > >  > >  > >  was clicked.
> > > >  > >  > >  Are there any unintended or harmful side effects to this?
> > > >  > >  > >  thanks,
> > > >  > >  > >  Anil
>
> > > >  > >  > --
> > > >  > >  > Romain Guywww.curious-creature.org
>
> > > >  > --
> > > >  > Romain Guywww.curious-creature.org
>
> > > --
> > > Romain Guywww.curious-creature.org
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to