Class: Toybox.WatchUi.SimpleDataField

Overview

Create a SimpleDataField.

A SimpleDataField is a special View that automatically provides Activity.Info once per second via the compute() method.

Just like in a DataField, a SimpleDataField automatically provides Activity.Info once per second via the compute() method. In exchange for the flexibility offered in a DataField, all field layout is handled automatically in a SimpleDataField.

A SimpleDataField requires two items:

  • A compute() method should return the value to be displayed by the SimpleDataField. Allowed types are Number, Float, Long, Double, Duration, and String.

  • A "label" variable, which should be assigned a String label for the field.

See Also:

Note:

The system will call the onUpdate() method inherited from View when a Data Field is displayed by the system. Because compute() and onUpdate() are asynchronous, there is no guarantee that compute() will be called before onUpdate(). For this reason, variables should never be initialized in compute().

Example:

A SimpleDataField that displays current heart rate

using Toybox.WatchUi;

class MySimpleHRField extends WatchUi.SimpleDataField {

    // Set the label of the field here
    function initialize() {
        SimpleDataField.initialize();
        label = "My Current HR";
    }

    // Specify the Activity info to display in the field here
    function compute(info) {
        return info.currentHeartRate;
    }
}

Since:

API Level 1.0.0

Supported Devices:

Instance Member Summary collapse

Instance Method Summary collapse

Instance Attribute Details

var label as Lang.String

The field label String.

Since:

API Level 1.0.0

Instance Method Details

compute(info as Activity.Info) as Lang.Numeric or Time.Duration or Lang.String or Null

Retrieve Activity.Info in a SimpleDataField.

This method is called once per second and automatically provides Activity.Info to the SimpleDataField object for display or additional computation. It is necessary to override compute() when implementing a SimpleDataField. The value to be displayed in the field must be returned by this method.

Parameters:

Example:

function compute(info) {
    return info.currentHeartRate;
}

Returns:

See Also:

Since:

API Level 1.0.0

initialize()

Constructor

Since:

API Level 1.0.0


Generated Dec 11, 2024, 8:58:44 AM