Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Refresh Image in ImageView

Another basic question: I try to refresh a image in an ImageView. I found this posting:
support.appcelerator.net
This doesn't work for me. I can't set a new image.url.

Here is my code:

var picRandom = 0;

var myImageView = Ti.UI.createImageView({ 
url:'http://anyurl.com/anypicture.jpg', 
width:480, 
height:320, 
top:0 
});

myView.add(myImageView);

var myImageViewUrl = 'http://anyurl.com/anypicture.jpg';

function doLoadData(){
    myImageView.url = myImageViewUrl; 
} 

myImageView.addEventListener('singletap', function(e){
    doLoadData();
});

but doLoadData does nothing. I altered the image url, but no matter what I do the myImageView stays the same…

Thanks in advance!

— asked April 1st 2010 by Niko B
  • imageview
  • iphone
  • refresh
0 Comments

5 Answers

  • I managed to refresh the image like this:

    img.url = 'myimage.jpg';
    img.hide();
    img.show();

    — answered April 22nd 2010 by Dan Tamas
    permalink
    0 Comments
  • Did you mean to add myImageView to myView? If you instead do Ti.UI.currentWindow.add(myImageView) what you're trying to do seems to work okay for me.

    — answered April 1st 2010 by Dan Giulvezan
    permalink
    0 Comments
  • Yeah I put the whole ImageView in another View and now it works fine.
    But every time I reload my image there is some loading image (a blue wave). How can I remove this image?
    Edit:
    preventDefaultImage removes this loading image, but there is still an opacity fade… how do i get rid of those?

    — answered April 1st 2010 by Niko B
    permalink
    0 Comments
  • I don't believe there's a way to prevent that right now. A word around might be to toggle the visibility to false and listen for the load event, then make the image visible again. That won't have the animation.

    Hmmm…just tried that and the load event doesn't seem to fire, so never mind that option for now.

    Another option might would be to use a webView instead of an imageView which won't have that same animation.

    — answered April 2nd 2010 by Dan Giulvezan
    permalink
    0 Comments
  • I'm trying to do something very similar. Did you ever get this resolved?

    — answered May 26th 2010 by Chris Dotson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.