Unable to set button icon with ImageDownloadService

323 views
Skip to first unread message

Andrew

unread,
Jun 8, 2014, 1:07:00 AM6/8/14
to codenameone...@googlegroups.com
Hi Guys,

I have an issue with ImageDownloadService. Below is my code. If I use a label, I can display the image downloaded from a server. But if I use a button, nothing is displayed. Please what am i doing wrong?

EncodedImage eImg = EncodedImage.findButton(f).getIcon();
Image i = URLImage.createToStorage(eImg, "MyStoredImage.jpg", "http://ImgURL.png", URLImage.RESIZE_SCALE);

//now set the ad image to downloaded image
findButton
(f).setIcon(i);

If I used findLabel(f).getIcon() instead and findLabel(f).setIcon(i), the code would work but for Button it does not. Why is this?

Thanks in advance.

If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS: Windos
Simulator
Device

Shai Almog

unread,
Jun 8, 2014, 1:18:20 AM6/8/14
to codenameone...@googlegroups.com, enu...@gmail.com
Hi,
URLImage != ImageDownloadService. They are completely separate approaches to the same problem.

Is it possible that the button doesn't have an icon and so eImg is null?
I'm assuming the URL is valid and you just entered an invalid URL as a sample, right?

enu...@gmail.com

unread,
Jun 8, 2014, 1:30:11 AM6/8/14
to codenameone...@googlegroups.com, enu...@gmail.com
Hi Shai,

Apologies for the mixup.

Yes the image URL is a sample one. I have a placeholder image already set as the default image for the button.
According to my reading, the downloaded image is supposed to be scaled to the size of the placeholder and then replace it.

Funny enough, I already implemented this in an early version of my application and it worked. I set the UIID of the Button to Label and when I can clicked on the image, it launched a browser.

Now it just isn't working. The code below is just a test code to test the functionality. I have checked the placeholder of the button is there.

Any thoughts?

Shai Almog

unread,
Jun 8, 2014, 10:03:33 AM6/8/14
to codenameone...@googlegroups.com, enu...@gmail.com
Hi,
if you use ImageDownloadService instead of URLImage e.g. ImageDownloadService.createImageToStorage(url, button, "idString", dimension); does that work?

enu...@gmail.com

unread,
Jun 8, 2014, 11:43:15 PM6/8/14
to codenameone...@googlegroups.com, enu...@gmail.com
Hey Shai,

It does work!

Still puzzled by the URLImage though. It worked previously for buttons but then just stopped.

The only changes I have made to my IDE is upgrade Netbeans from 7.4 to 8.0. Then re-install the codenameone plugin.

Anyways my issue is resolved so thanks.
Reply all
Reply to author
Forward
0 new messages