Question

I'm working on Titanium 2.1.3 and deploying for both iOS and Android. I'm having trouble displaying images on ImageView on Android in a TableView, if I do something like clicking on the search bar and show the keyboard then the images are shown or if I scroll the TableView the images appear and disappear with no apparent reason. It seems that unless I do something that forces a layout refresh on the TableView, the images aren't rendered. The images are being loaded the same way in both Android and iOS, which is like this:

var itemIconHolder = Titanium.UI.createView({
    width : '100dp',
    left : '55dp',
    height : "100%"
});

var itemIcon = Titanium.UI.createImageView({
    left : '0dp',
    height : '100%',
});

var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
itemIcon.image = f;

itemIconHolder.add(itemIcon);

This problem doesn't happen in iOS, on iOS devices/simulator the behaviour is normal and flawless, but on Android devices/emulator it happens. Do I have to load the images differently in Android? Am I missing something? I hope someone could help me in this one. Thanks in advance.

EDIT

I tried these approaches:

itemIcon.image = f.read();

and

itemIcon.image = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);

but the images still aren't rendered until I make something that causes the TableView to refresh in some way.

Was it helpful?

Solution

I found a workaround for this particular issue on Android. Since it takes a layout refresh for the images to be rendered properly, what I did was to animate the table, moving it 1dp in a direction and at the completition of said animation I animated it again to return it to its original position. This is the code I used:

var table_bottom = '-1dp'

var tableAnimation = Ti.UI.createAnimation({
    bottom : table_bottom,
    duration : 100
});
tableAnimation.addEventListener('complete', function(e){
    var table_bottom = '50dp';
    if (osname === 'android') 
    {
        table_bottom = '0dp'
    }
    table.animate({
        bottom : table_bottom,
        duration : 100
    });
});

I've encountered this kind of problem with both Titanium SDK 2.1.3 and Titanium 3.0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top