diff --git a/examples/gui/demo_listview.c b/examples/gui/demo_listview.c index 13c0d5cc7..a66a3d179 100644 --- a/examples/gui/demo_listview.c +++ b/examples/gui/demo_listview.c @@ -5,6 +5,8 @@ #include static rtgui_workbench_t* workbench = RT_NULL; +static rtgui_view_t* _view = RT_NULL; +static rtgui_image_t* return_image = RT_NULL; static void listitem_action(void* parameter) { @@ -33,35 +35,44 @@ static void listitem_action(void* parameter) rtgui_win_show(win, RT_FALSE); } -static struct rtgui_list_item items[] = +static void return_action(void* parameter) +{ + if (_view != RT_NULL) + { + rtgui_view_destroy(_view); + _view = RT_NULL; + } +} + +static const struct rtgui_list_item items[] = { {"列表项1", RT_NULL, listitem_action, (void*)1}, {"列表项2", RT_NULL, listitem_action, (void*)2}, {"列表项3", RT_NULL, listitem_action, (void*)3}, {"列表项4", RT_NULL, listitem_action, (void*)4}, {"列表项5", RT_NULL, listitem_action, (void*)5}, + {"返回", RT_NULL, return_action, RT_NULL}, }; static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event) { /* create a file list view */ rtgui_rect_t rect; - rtgui_list_view_t *view; workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget)); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); - view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item), &rect); - rtgui_workbench_add_view(workbench, RTGUI_VIEW(view)); + _view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item), &rect); + rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view)); /* 模式显示视图 */ - rtgui_view_show(RTGUI_VIEW(view), RT_FALSE); + rtgui_view_show(RTGUI_VIEW(_view), RT_FALSE); } rtgui_view_t* demo_listview_view(rtgui_workbench_t* workbench) { rtgui_rect_t rect; - rtgui_view_t* view; + rtgui_list_view_t *view; rtgui_button_t* open_btn; view = demo_view(workbench, "列表视图演示");