0

我正在尝试实现一个按钮操作,当按下 Select 按钮时在我的 ScrollLayer 上显示文本。我用了:

scroll_layer_set_click_config_onto_window(scrollLayer, window);

自动设置 BUTTON_UP 和 BUTTON_DOWN 回调函数(滚动)。那么我想设置一个 BUTTON_SELECT 回调函数。我写了这两个函数:

//Performs an action whenver the 'select' button is pressed
void select_click_handler(ClickRecognizerRef recognizer, void *ctx) {
    text_layer_set_text(textLayer, "You pressed select");
}

//Links the select button to a function, select_click_handler
void click_config_provider(void *ctx) {
    window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
}

在我的初始化程序中,我有:

void init() {
    window = window_create();
    window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
    });
    window_set_click_config_provider(window, click_config_provider);
    window_stack_push(window,true);
} 

当我运行它时,它编译并安装在手表上就好了,但是,当我点击选择按钮时,什么也没有发生。当我注释掉scroll_layer_set_click_config_onto_window(scrollLayer, window); 它时,它就像它应该的那样工作。

有没有办法覆盖选择按钮回调而不必注释掉上面的行?

提前致谢!

4

2 回答 2

1

scroll_layer_set_callbacks()我在这里找到了一个使用函数的简单解决方法:

http://forums.getpebble.com/discussion/11432/scroll-layer-set-callbacks

于 2014-05-29T18:58:01.827 回答
1

Now you can find it in Pebble official document(SDK 2.0).

ScrollLayer // Pebble Developers http://developer.getpebble.com/docs/c/User_Interface/Layers/ScrollLayer/

The SELECT button can be configured by installing a click configuration provider using scroll_layer_set_callbacks().

于 2015-05-28T00:16:01.280 回答