Issues adding rows to a picker column

You must Login before you can answer or comment on any questions.

SDK 2.1.3.GA, targeting Android 2.3.3 onwards

I'm having problems with the following bit of code. It's setting up the columns for an 'hours, minutes, seconds' picker, and it works perfectly, but the performance is really terrible. It all comes down to the "pickerColumns.push..." line. That line alone takes 3 seconds to create a column with 60 rows, giving a delay of about 8 seconds for the screen to respond - this is on a Nexus (i9250)

I'm also see lines (for every picker row, i.e. 144 lines) in the console saying ".... Nativeview is null". This is appearing after this section of code has completed.

var pickerColumns = [];
 
for (var i = 0; i < data.length; i++) {
    var pickerRows = [];
 
    for (var j = 0; j < data[i].length; j++) {
        pickerRows.push(Ti.UI.createPickerRow({
            title : data[i][j]
        }));
    }
    pickerColumns.push(Ti.UI.createPickerColumn({
        rows : pickerRows
    }));
}
Any clues why this is so slow? Is there a better way to achieve this?

Thanks for looking

2 Answers

the 'rows' property is marked as read-only for a PickerColumn

the problem should come from here. use addRow() instead

rows : Titanium.UI.PickerRow[] READONLY

While this property is currently writable on Android, changing its value is strongly discouraged.

— answered 7 months ago by Vince
answer permalink
1 Comment
  • Thanks Vince, that sounded like it was going to resolve it, it certainly simplifies the code, but it doesn't seem to make any difference. This is what I changed it to:

    for (var i = 0; i < data.length; i++) {
        pickerColumns[i] = Ti.UI.createPickerColumn();
        for (var j = 0; j < data[i].length; j++) {
            pickerColumns[i].addRow(Ti.UI.createPickerRow({
                title : data[i][j]
            }));
        }
    }
    Whilst I should have spotted the READONLY, the KitchenSink app actually does it by using 'rows' too!

    — commented 7 months ago by Nigel Harrison

After further investigation it appears that this problem had precious little to do with the code, and everything to do with where the code was being executed. I was trying to create the picker on a window 'open' event. If I move the code to a 'click' event, for example on a button, then the performance is perfectly acceptable - i.e. milliseconds, rather than seconds.

If anyone knows why this is the case please tell me!

Your Answer

Think you can help? Login to answer this question!