image.png

    示例代码:

    1. static lv_obj_t * list1;
    2. static void event_handler(lv_event_t * e)
    3. {
    4. lv_event_code_t code = lv_event_get_code(e);
    5. lv_obj_t * obj = lv_event_get_target(e);
    6. if(code == LV_EVENT_CLICKED) {
    7. LV_LOG_USER("Clicked: %s", lv_list_get_btn_text(list1, obj)); // 打电话, 打开led
    8. }
    9. }
    10. void lv_example_list_1(void)
    11. {
    12. /*Create a list*/
    13. list1 = lv_list_create(lv_scr_act());
    14. lv_obj_set_size(list1, 240, 280);
    15. lv_obj_center(list1);
    16. /*Add buttons to the list*/
    17. lv_obj_t * btn;
    18. lv_list_add_text(list1, "Basic");
    19. btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "Label");
    20. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    21. btn = lv_list_add_btn(list1, LV_SYMBOL_DIRECTORY, "Button");
    22. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    23. btn = lv_list_add_btn(list1, LV_SYMBOL_SAVE, "Img");
    24. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    25. btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "ButtonMatrix");
    26. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    27. btn = lv_list_add_btn(list1, LV_SYMBOL_EDIT, "Textarea");
    28. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    29. lv_list_add_text(list1, "Layout");
    30. btn = lv_list_add_btn(list1, LV_SYMBOL_BLUETOOTH, "Grid");
    31. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    32. btn = lv_list_add_btn(list1, LV_SYMBOL_GPS, "Flex");
    33. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    34. btn = lv_list_add_btn(list1, LV_SYMBOL_USB, "USB");
    35. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    36. btn = lv_list_add_btn(list1, LV_SYMBOL_BATTERY_FULL, "Battery");
    37. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    38. lv_list_add_text(list1, "Advanced");
    39. btn = lv_list_add_btn(list1, LV_SYMBOL_OK, "List");
    40. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    41. btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Chart");
    42. lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
    43. }