Description
I have a fairly long ddlist (~600 items) and I am trying to set a default position based on the current setting. This works fine, but whenever I create the drop-down list it always starts at the top of the list rather than the selected option.
Code to reproduce
lv_obj_t *mylist = lv_ddlist_create(lv_scr_act(), NULL);
lv_ddlist_set_options(mylist, list_of_options);
lv_ddlist_set_stay_open(mylist, true);
lv_ddlist_open(mylist, LV_ANIM_OFF);
lv_ddlist_set_selected(ddl_tz, index); // This sets the index correctly, but the ddlist is still at the top
Solution
I’ve figured it out as I was typing this all out. This is an order of operations issue, and perhaps an opportunity for improvement. If I move the lv_ddlist_set_selected() call to just before I open the list then it appears at the offset of my index. Arguably it should move the list to the position of the selected item after it’s opened as well. In either case I’ve figured out my own question and will leave this here in case anyone else runs into this!
lv_obj_t *mylist = lv_ddlist_create(lv_scr_act(), NULL);
lv_ddlist_set_options(mylist, list_of_options);
lv_ddlist_set_selected(ddl_tz, index); // Moving this up here fixes my issue
lv_ddlist_set_stay_open(mylist, true);
lv_ddlist_open(mylist, LV_ANIM_OFF);