List eventhandler

Description

What MCU/Processor/Board and compiler are you using?

stm32f746-DISCO/ cube-ide

What LVGL version are you using?

v8.1

What do you want to achieve?

list eventhandler

What have you tried so far?

i had created the listbox of some items, now i am looking to Handel the list by event handler. is is possible and how to do it?

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(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);
    if(code == LV_EVENT_VALUE_CHANGED) {
    	lv_label_set_text(label[0], "1");
//        uint32_t id = lv_btnmatrix_get_selected_btn(obj);
//        const char * txt = lv_btnmatrix_get_btn_text(obj, id);
//
//        LV_LOG_USER("%s was pressed\n", txt);
    }
}


static void CreateContent(){
	lv_obj_t * list = lv_list_create(window);
	lv_obj_set_size(list, 350, 225);
	lv_obj_align(list, LV_ALIGN_BOTTOM_LEFT, 0, 0);

	for(uint8_t btn_cnt = 1; btn_cnt <= 100; btn_cnt++) {
		char buf[32];
		lv_snprintf(buf, sizeof(buf), "NODE ID: %d, T: VW, R: 0.100 mm", (int)btn_cnt);
		lv_list_add_btn(list, LV_SYMBOL_LIST, buf);


//		lv_obj_set_event_cb(list, btn_event_cb);

		lv_obj_add_event_cb(list, event, LV_EVENT_ALL, btn_cnt);

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Your mistake was in:

lv_obj_add_event_cb(list, event, LV_EVENT_ALL, btn_cnt);

You need to change it to:

lv_obj_t* btn //outside the loop

//Inside the loop
btn = lv_list_add_btn(list, LV_SYMBOL_LIST, buf);
lv_obj_add_event_cb(btn, event, LV_EVENT_ALL, btn_cnt);