问题
I am a newbie to Titanium. I am creating a picker in Titanium which loads a set of records from my local sqlite database.
Whenever I scroll the picker, for the first time there seems to be a small lag in scrolling. That is, when user scrolls the picker, there is a lag for few seconds and then users are allowed to scroll records continuously. This lags happens only for the first time.
Can anyone please guide me how to fix this scroll lag.
My code is as follows:
function CREATEPICKER(rows, x, y, width, sel, initialValue) {
var picker = Ti.UI.createPicker({left: x, height: Ti.App.pickerHeight, top: y, plat: '', width : width});
var data =[];
var v, selectedrow;
data[0]=Ti.UI.createPickerRow({title: initialValue, font:{fontSize: 48} });
var j = 1;
while (rows.isValidRow())
{
v = rows.fieldByName('id');
if((v != null) && (v != '') && (v != 'NULL')) {
if(v == sel) selectedrow = j;
data[j]=Ti.UI.createPickerRow({title: v, fontSize: 48 });
j++;
}
rows.next();
}
if(selectedrow > 0) picker.setSelectedRow(0,selectedrow);
picker.selectionIndicator = true;
picker.add(data);
return(picker);
}
Can someone please guide me.
Thank You.
回答1:
Try doing this, when adding items to your data array:
data[j] = Ti.UI.createPickerRow( {
title : j++,
font : {
fontSize : 48
}
} );
来源:https://stackoverflow.com/questions/21330763/titanium-picker-scrolling-lags-for-the-first-time