Titanium Appcelerator - Picker setSelectedRow
Although in some post, they said that Picker.setSelectedRow is bugged, I think otherwise.
In the API, it is said that setSelectRow must be called after the picker is displayed. Display means the picker must be rendered and the best case to use it is after calling Window.open().
Thus, 2 ways to use it
First way
var win = Ti.UI.createWindow({ //... add some configuration });
var picker = Ti.UI.createPicker({ //... add some configuration });
//... add some data....
win.add(picker);
win.open();
//setting to column 0, row 1, with no animation
picker.setSelectedRow(0, 1, false);
Second way is to put setSelectedRow in window open event
var picker = null;
function Foo(){
var win = Ti.UI.createWindow({ //... add some configuration });
picker = Ti.UI.createPicker({ //... add some configuration });
//... add some data....
win.add(picker);
picker.setSelectedRow(0, 1, false);
Both way ensure picker.setSelectedRow(0, 1, false); is called after Window is opened
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Picker-object
In the API, it is said that setSelectRow must be called after the picker is displayed. Display means the picker must be rendered and the best case to use it is after calling Window.open().
Thus, 2 ways to use it
First way
var win = Ti.UI.createWindow({ //... add some configuration });
var picker = Ti.UI.createPicker({ //... add some configuration });
//... add some data....
win.add(picker);
win.open();
//setting to column 0, row 1, with no animation
picker.setSelectedRow(0, 1, false);
Second way is to put setSelectedRow in window open event
var picker = null;
function Foo(){
var win = Ti.UI.createWindow({ //... add some configuration });
picker = Ti.UI.createPicker({ //... add some configuration });
//... add some data....
win.add(picker);
win.addEventListener("open", onOpen);
win.open();
}
function onOpen(){
//setting to column 0, row 1, with no animationpicker.setSelectedRow(0, 1, false);
}
Both way ensure picker.setSelectedRow(0, 1, false); is called after Window is opened
When setSelectedRow is use, a change event could be trigger if the there is a change in selected item.
One may think that on window open, picker.setSelectedRow will definitely trigger a change event because there is no selected item prior to window open. You are half correct because iPhone will trigger a change even while Android will not. Please take note of this.
ReferenceOne may think that on window open, picker.setSelectedRow will definitely trigger a change event because there is no selected item prior to window open. You are half correct because iPhone will trigger a change even while Android will not. Please take note of this.
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Picker-object
Comments
Post a Comment