Class: Toybox.WatchUi.TextPicker

Overview

A representation of an on-screen text picker.

A TextPicker is a special View that provides a way to specify textual input in an app. A TextPicker is pushed using pushView(), and provides a TextPickerDelegate as the input delegate. A default value can be provided and is displayed as editable text with the cursor placed at the end.

See Also:

Note:

The look and feel of a text picker is device-specific.

Example:

using Toybox.WatchUi;

// A string to display on the screen
var screenMessage = "Press Menu to Enter Text";
var lastText = "";

class MyTextPickerDelegate extends WatchUi.TextPickerDelegate {

    function initialize() {
        TextPickerDelegate.initialize();
    }

    function onTextEntered(text, changed) {
        screenMessage = text + "\n" + "Changed: " + changed;
        lastText = text;
    }

    function onCancel() {
        screenMessage = "Canceled";
    }
}

class MyInputDelegate extends WatchUi.InputDelegate {
    function initialize() {
        InputDelegate.initialize();
    }

    function onKey(key) {
        if (WatchUi has :TextPicker) {
            if (key.getKey() == Ui.KEY_MENU) {
                WatchUi.pushView(
                    new WatchUi.TextPicker(lastText),
                    new MyTextPickerDelegate(),
                    WatchUi.SLIDE_DOWN
                );
            }
        }
        return true;
    }
}

Since:

API Level 1.1.0

Supported Devices:

Instance Method Summary collapse

Instance Method Details

initialize(initialText as Lang.String)

Constructor

Parameters:

  • initialText(Lang.String)

    The initial text for the TextPicker

Since:

API Level 1.1.0


Generated Apr 17, 2024 9:40:39 AM