Description
Clicking on an item in the dropdown list always displays the last item.
It was confirmed that lv_dropdown_get_selected_str() is continuously called by the events (LV_EVENT_PRESSED, LV_EVENT_SHORT_CLICKED, LV_EVENT_RELEASED) occurring while clicking the dropdown list. Is this normal operation?
When the lv_dropdown_get_selected_str() function is called by LV_EVENT_VALUE_CHANGED when another item is clicked, the sel_opt_id_orig
value does not change and always points to the last index.
I’d appreciate if you let me know why this is happening and how to fix it.
What MCU/Processor/Board and compiler are you using?
STM32F767IIT
Custom board
FreeRTOS v10.2.1
What LVGL version are you using?
7.10.1
What do you want to achieve?
What have you tried so far?
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
static void event_handler1(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
char buf[32];
lv_dropdown_get_selected_str(obj, buf, sizeof(buf));
}
}
static void GUI_SelectProgram(void)
{
touch_init();
// Create a window
if(win == NULL)
{
screen = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(screen, 480, 320);
win = lv_win_create(screen, NULL);
}
// window
lv_win_set_title(win, "Select Program");
lv_coord_t header_height = lv_win_get_header_height(win);
lv_win_set_content_size(win, 480, 320-header_height);
/*Create a normal drop down list*/
ddlist = lv_dropdown_create(lv_scr_act(), NULL);
lv_dropdown_set_options(ddlist, "Apple\n"
"Banana\n"
"Orange");
lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
lv_obj_set_event_cb(ddlist, event_handler1);
while(true)
{
vTaskDelay(1);
lv_task_handler();
if (CURR_GUI_STATE != GUI_STATE_MAIN){
lv_win_clean(win);
break;
}
}
}