Search code examples
iphonetitaniumtitanium-mobile

How i add almost 1000 Views in ScrollView for iphone and Android?


I am using Titanium SDK 3.0.0. GA. I have need almost 1000 Views in one Scroll View When i create 1000 Views in Loop and add in Array. after this pass in ScrollableView. It take a long time in Device and Some Time Application should be crashed. How i manage this problem. Please, Help me. Thanks,

var views_array=[];
for(var i=0;i<1000;i++){
    var view = Ti.UI.createView({
        height : 100,
        width : 100,
        backgroundColor : "#f00",   
    });
    views_array.push(view);
}

var main_scroll_label_view = Ti.UI.createScrollableView({
    width : Ti.UI.FILL,
    showPagingControl : false,
    backgroundColor : "transparent",
    views : views_array,
});

Solution

  • You need to load views "lazily". Set up a delegate for your scrollView that responds anytime the view is moved.

    When the view is scrolled figure out which sub views need to be shown and dump the ones you don't need anymore. UITableView is essentially the same thing. It's just a scrollView that only loads what's visible.