Picker wheel: select a value programatically

Hi.

Is is possible to select a value programatically in a picker wheel after it is created?

I need to change the picker wheel selected row when user touchs an image.

I have tried to change the startIndex attribute, but it doesn’t work… 

Thank you in advance.

    Jose Antonio

Hi Jose,

At this time, there’s not a function to move/manipulate the pickerWheel that doesn’t involve the user actually touching it. Could you create a new pickerWheel in the same location (with a new starting index) and remove the previous one? I think if the visual assets were already loaded into memory, and you did this in the same time-step, it would appear virtually seamless.

Best regards,

Brent

Hi Brent.

Yes, it could be possible, but… it shouldn’t show the movement transitioning from current item to final item (in a few millis). Your idea would produce a sudden change. My goal is show to user how items move until a target position. Are there another solution? Perhaps tableview…

Regards,

    Jose Antonio

Hi @joseanquiles,

I dug down into the core of the widget object using “pairs()” and located the internal function (not normally exposed) which should let you control the scrolling programmatically. Note that this method is not officially “supported” and I can’t promise that it won’t cause other issues or break something else… so, use it at your own risk.

During the time you are forcing the scroll, I would definitely prevent any user interaction on the wheel, for example, by placing an invisible but touch-sensitive blocking rectangle over it, so the user can’t attempt to scroll the wheel at the same time it’s doing so programmatically.

Here’s a quick example, assuming you have a picker widget already created named “pickerWheel”:

[lua]

local gotoIndex = 3

local function forceScroll()

   pickerWheel._view._columns[1]:scrollToIndex( gotoIndex )

end

timer.performWithDelay( 1000, forceScroll )

[/lua]

This will force the first column to scroll to index 3 after 1000 milliseconds. To scroll a different column, just change the index “[1]” to “[2]” or whatever column you need to scroll.

Best regards,

Brent

Hi Jose,

At this time, there’s not a function to move/manipulate the pickerWheel that doesn’t involve the user actually touching it. Could you create a new pickerWheel in the same location (with a new starting index) and remove the previous one? I think if the visual assets were already loaded into memory, and you did this in the same time-step, it would appear virtually seamless.

Best regards,

Brent

Hi Brent.

Yes, it could be possible, but… it shouldn’t show the movement transitioning from current item to final item (in a few millis). Your idea would produce a sudden change. My goal is show to user how items move until a target position. Are there another solution? Perhaps tableview…

Regards,

    Jose Antonio

Hi @joseanquiles,

I dug down into the core of the widget object using “pairs()” and located the internal function (not normally exposed) which should let you control the scrolling programmatically. Note that this method is not officially “supported” and I can’t promise that it won’t cause other issues or break something else… so, use it at your own risk.

During the time you are forcing the scroll, I would definitely prevent any user interaction on the wheel, for example, by placing an invisible but touch-sensitive blocking rectangle over it, so the user can’t attempt to scroll the wheel at the same time it’s doing so programmatically.

Here’s a quick example, assuming you have a picker widget already created named “pickerWheel”:

[lua]

local gotoIndex = 3

local function forceScroll()

   pickerWheel._view._columns[1]:scrollToIndex( gotoIndex )

end

timer.performWithDelay( 1000, forceScroll )

[/lua]

This will force the first column to scroll to index 3 after 1000 milliseconds. To scroll a different column, just change the index “[1]” to “[2]” or whatever column you need to scroll.

Best regards,

Brent