Passing user data to lv_obj_add_event_cb

Hi
I am to make a radio button from the check box. The matter I have faced is that I don’t know really how to pass user data arguments into the function.
The code I have used so far with loads of warnings that works is as follows.

lv_obj_t * ViewSelection[4];
static void VIEW_event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    char userdata = lv_event_get_user_data(e);

    if(code == LV_EVENT_RELEASED)
    {
        switch(userdata)
        {
            case 1:
                lv_obj_clear_state(ViewSelection[1], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[2], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[3], LV_STATE_CHECKED);
                break;
            case 2:
                lv_obj_clear_state(ViewSelection[0], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[2], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[3], LV_STATE_CHECKED);
                break;
            case 3:
                lv_obj_clear_state(ViewSelection[0], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[1], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[3], LV_STATE_CHECKED);
                break;
            case 4:
                lv_obj_clear_state(ViewSelection[0], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[1], LV_STATE_CHECKED);
                lv_obj_clear_state(ViewSelection[2], LV_STATE_CHECKED);
                break;
        }
    }
}

lv_obj_t* CreateScreenMenuView(void)
{
    ScreenMenu = lv_obj_create(NULL);
    lv_scr_load_anim(ScreenMenu,LV_SCR_LOAD_ANIM_FADE_ON, 200, 0, true);

    for (char i = 0;i<4;i++)
        {
            ViewSelection[i] = lv_checkbox_create(ScreenMenu);
            lv_obj_add_event_cb(ViewSelection[i],VIEW_event_handler,LV_EVENT_RELEASED,i+1);
        }
    lv_obj_set_pos(ViewSelection[0],100,100);
    lv_obj_align_to(ViewSelection[1],ViewSelection[0],LV_ALIGN_OUT_BOTTOM_LEFT,0,30);
    lv_obj_align_to(ViewSelection[2],ViewSelection[1],LV_ALIGN_OUT_BOTTOM_LEFT,0,30);
    lv_obj_align_to(ViewSelection[3],ViewSelection[2],LV_ALIGN_OUT_BOTTOM_LEFT,0,30);
    return ScreenMenu;
}

The warning says
" passing argument 4 of ‘lv_obj_add_event_cb’ makes pointer from integer without a cast [-Wint-conversion] "

The warning is caused by the fact that our APIs expect a pointer as user data, however, we do nothing with the pointer besides storing it and returning it to you, so you should be able to safely cast i to void * to get rid of the warning, and then cast the result of lv_event_get_user_data back to char.

Thank you.
But then it would through another warning which is
“warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]|”
“warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|”
I am looking for a strong method. How should I do that?

To solve that warning, I think you can use uintptr_t or intptr_t instead of char. v8 doesn’t allow you to change the user data type directly.

The matter in general is casting, not what to cast.
I searched the forum and found some had used structs instead of pure integeres in this cse for user data.

The problem is solved by passing struct into the user data.