Generic Picker / PickerDelegate difficulties

Has anybody built a simple working implementation using the Picker / Picker delegate? Whenever I try to run it, I get these errors:
Failed invoking <symbol>
Symbol Not Found Error
Symbol Not Found Error


Here's my test code

class MyNumberFactory extends Ui.PickerFactory{
function getDrawable(item, isSelected){
return new Ui.Text({:text=>item.toString()});
}
function getSize(){ return 10; }
function getValue(item){ return item;}
}

class MyPickerDelegate extends Ui.PickerDelegate{
function onAccept( values ){ return true; }
function onCancel( ){ return true; }
}
class MyInputDelegate extends Ui.BehaviorDelegate {
function onMenu(){
Ui.pushView(new Picker({:title=>"Number Picker", :pattern=>[new MyNumberFactory()]}),
new MyPickerDelegate(),
Ui.SLIDE_IMMEDIATE );
return true;
}
}
  • Is this on simulator or one of the devices? If it is on a device, are you running the CIQ 1.2 beta software?
  • This is the error I'm getting on the simulator.
    If I install it on a VivoActive device running CIQ 1.2, it just locks up when the method above would be called.

    Thanks for letting me know it isn't in the simulator yet, though. That will save me from barking up that tree.
  • The Picker actually is supported in the simulator for the current 1.2.0 beta SDK. There are two issues with the code, both of which will cause the symbol not found error.

    Ui.pushView(new Picker({:title=>"Number Picker", :pattern=>[new MyNumberFactory()]}),
    new MyPickerDelegate(),
    Ui.SLIDE_IMMEDIATE );


    Unless you've created a class called Picker that extends WatchUi.Picker, you'll want to create a new Ui.Picker. It's not necessary to extend Ui.Picker, but if you do you'll have a chance to do some stuff in onUpdate() before the Picker elements are drawn. Also, everything in the Picker needs to be a WatchUi.Drawable. That means :title needs to be set to a WatchUi.Text object instead of a String. This is a case where we could detect that it's a String and convert it to a WatchUi.Drawable for you, so I've added a ticket to support this.
  • Thanks Kyle. Turns out the issue was as simple as leaving out the "Ui." (and returning a Drawable.)

    I'll post the updated code as an example to others when I get a chance.
  • Here's my simple Picker demo
    using Toybox.WatchUi as Ui;
    using Toybox.System as Sys;
    using Toybox.Graphics as Gfx;

    class MyNumberFactory extends Ui.PickerFactory{
    function getDrawable(item, isSelected){
    return new Ui.Text({:text=>item.toString(),
    :color=>Gfx.COLOR_WHITE,
    :font=>Gfx.FONT_NUMBER_THAI_HOT,
    :justification=>Gfx.TEXT_JUSTIFY_LEFT});
    }
    function getSize(){ return 10; }
    function getValue(item){ return item;}
    }

    class MyPickerDelegate extends Ui.PickerDelegate{
    function onAccept( values ){
    for(var i = 0; i< values.size(); i++){
    Sys.println(values);
    }
    Ui.popView(Ui.SLIDE_DOWN);
    return true;
    }
    function onCancel( ){ return true; }
    }
    class MyInputDelegate extends Ui.BehaviorDelegate {
    function onMenu(){
    Ui.pushView(new Ui.Picker({:title=>new Ui.Text({:text=>"Number Picker"}),
    :pattern=>[new MyNumberFactory()],
    :defaults=>[0]}),
    new MyPickerDelegate(),
    Ui.SLIDE_UP );
    return true;
    }
    }[/CODE]