Thursday 15 January 2015

android - Catching errors loading Remote Images in Titanium ImageView -



android - Catching errors loading Remote Images in Titanium ImageView -

i'm using titanium sdk 3.4.0 ga, developing android app load remote images web server imageview.

the problem comes when device lost connectivity during load of images, so, need way grab error (timeout, 404...) , set "imagenotavailable". i'm using network link conditioner macosx reproduce scenario, low latency, lost of packets...

to prove utilize next code in test.js (alloy controller) , simple view imageview id='imageview' in test.xml.

sometimes, throws exception:

tidownloadmanager: (pool-4-thread-1) [45929,118581] exception downloading http://...

but not (remote connection timeout seems infinite), anyway exception , without can't grab (probably due asynchronous request) nor fires error event.

function imagenotavailable(e) { ti.api.info('error loading image:'+json.stringify(e)); $.imageview.image = "/imagenotavailable.png"; } function onload(e) { ti.api.info('image loaded:'+json.stringify(e)); } function setimageandroid(image) { try{ $.imageview.image = 'http://....'; }catch(e){ $.imageview.fireevent("error"); } $.imageview.addeventlistener("error", imagenotavailable); $.imageview.addeventlistener("load", onload); }

excuse bad english! thanks!

have tried adding event listeners before setting imageview's image property?

android appcelerator titanium-alloy

No comments:

Post a Comment