Search code examples
tizentizen-wearable-sdktizen-native-app

How to update a text into a Label?


I'm developing a Tizen native app for a watch face.

I created the base gui using the default create_base_gui function:

typedef struct appdata {
    Evas_Object *win;
    Evas_Object *conform;
    Evas_Object *label;
    Evas_Object *box;
} appdata_s;

static void
create_base_gui(appdata_s *ad, int width, int height)
{
    int ret;
    watch_time_h watch_time = NULL;

    /* Window */
    ret = watch_app_get_elm_win(&ad->win);
    if (ret != APP_ERROR_NONE) {
        dlog_print(DLOG_ERROR, LOG_TAG, "failed to get window. err = %d", ret);
        return;
    }

    evas_object_resize(ad->win, width, height);

    /* Conformant */
    ad->conform = elm_conformant_add(ad->win);
    evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    elm_win_resize_object_add(ad->win, ad->conform);

    /* Box */
    ad->box = elm_box_add(ad->conform);
    evas_object_show(ad->box);
    elm_object_content_set(ad->conform, ad->box);

    ad->label = elm_label_add(ad->box);
    evas_object_size_hint_align_set(ad->label, 0.5, 0.5);
    elm_object_text_set(ad->label, "Time");
    evas_object_show(ad->label);
    elm_box_pack_end(ad->box, ad->label);

    ret = watch_time_get_current_time(&watch_time);
    if (ret != APP_ERROR_NONE)
        dlog_print(DLOG_ERROR, LOG_TAG, "failed to get current time. err = %d", ret);

    update_watch(ad, watch_time, 0);
    watch_time_delete(watch_time);

    /* Show window after base gui is set up */
    evas_object_show(ad->win);
}

In the update_watch function I'm trying to update the text using this code:

static void
update_watch(appdata_s *ad, watch_time_h watch_time, int ambient)
{
    char watch_text[TEXT_BUF_SIZE];
    int hour24, minute, second;
    int time;

    if (watch_time == NULL)
        return;

    watch_time_get_hour24(watch_time, &hour24);
    watch_time_get_minute(watch_time, &minute);
    watch_time_get_second(watch_time, &second);

    elm_object_text_set(ad->label, "Update" );
}

But it does not work.

What's the error?


Solution

  • at the first. You miss a evas_object_show(ad->conform); It makes invisible controls under conform. (box and label.)

    And if your update watch function not work in every time, make it is called in time_tick callback in watch_app_lifecycle_callback_s structure.