How to create a obj without copying the callback function

Description

I have created several btns,and the later ones were created based on the first one,which using the “copy” thing. I only gave the first btn the callback function, but I found the others btn all entered that callback function which should be not, is there a better way to aoid this?

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

STM-32

What do you want to achieve?

Create a object,for example,btn ,using lv_btn_create(lv_scr_act(),btn_1) but avoid coping the callback of btn_1

What have you tried so far?

I think if i set the callback funcation for each btn separately should work, but some btns needn’t callback function, I just wonder is there any better way to do this?

Code to reproduce

/You code here/

 lv_obj_t* set_btn ;
set_btn = lv_btn_create(set_cont,set_btn);
  lv_obj_set_size(set_btn,btn_width,btn_height);
  TS_OutputText(1,"2th btn:0x%x",set_btn);
  lv_obj_set_event_cb(set_btn,Set_FunBtn_DisplayMode_event);

  lv_obj_t* obj_cb = lv_cb_create(set_page,NULL);
  lv_obj_align(obj_cb,set_btn,LV_ALIGN_IN_RIGHT_MID,40,0);
  lv_cb_set_text(obj_cb,"1");
  lv_obj_set_event_cb(obj_cb,set_Cb_event);
  SecLayer_Set.cb_DisMode = obj_cb;
  TS_OutputText(1,"display mode checkbox:0x%x",obj_cb);

  btn_label = lv_label_create(set_btn,NULL);
  lv_label_set_text(btn_label,"顯示方式");

  set_btn = lv_btn_create(set_cont,set_btn);
  lv_obj_set_size(set_btn,btn_width,btn_height);
  TS_OutputText(1,"3th btn:0x%x",set_btn);

  btn_label = lv_label_create(set_btn,NULL);
  lv_label_set_text(btn_label,"語音開關");

  set_btn = lv_btn_create(set_cont,set_btn);
  lv_obj_set_size(set_btn,btn_width,btn_height);
  TS_OutputText(1,"4th btn:0x%x",set_btn);

  btn_label = lv_label_create(set_btn,NULL);
  lv_label_set_text(btn_label,"語音音量");

## Screenshot and/or video
  As you can see upstair,  all btns enter the first callback function "Set_FunBtn_DisplayMode_event".

You should be able to call lv_obj_set_event_cb(<btnobj>, NULL) to remove the callback.

1 Like