cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup callback for a Radio Button Group ?

BParh.1
Senior III

So let say I have a group of radio button like this:

touchgfx::RadioButtonGroup<5> radioButtonGroup1;

And whenever use select every radio button inside the group, I want to trigger the same callback handler.

How can I achieve this?

'

1 ACCEPTED SOLUTION

Accepted Solutions
BParh.1
Senior III

Ok finally I got it:

//in .hpp
touchgfx::Callback<MainView, const touchgfx::AbstractButton&> cbRadioBtnGroup;
void cbRadioBtnGroupHandler(const touchgfx::AbstractButton& src);
 
 
// in .cpp
MainView::MainView() :
    cbRadioBtnGroup(this, &MainView::cbRadioBtnGroupHandler) {
    radioButtonGroup.setRadioButtonSelectedHandler(cbRadioBtnGroup);
}
 
MainView::
void MainView::cbRadioBtnGroupHandler(const touchgfx::AbstractButton& src) {
    if(&src == &radioButton1) {
        // handle for radioButton1 selection
    }
    else if(&src == &radionButton2) {
       // handle for radioButton2 selection
   }
   ....
   else {}
 
 
}

View solution in original post

4 REPLIES 4
ktrofimo
Senior III

It looks like only individual callbacks from every button are available​

BParh.1
Senior III

so far I did this way but it has build error:

in .hpp

Callback<HomeView, const RadioButtonGroup<5>&, const ClickEvent> cbRadioBtn;
 
void cbRadioBtnHandler(const RadioButtonGroup<6>& src, const ClickEvent ev) {
 
      // handle selected radio button
 
}

in constructor:

HomeView::HomeView():
    cbRadioBtn(this, &HomeView::cbRadioBtnHandler) {
 
}
 
HomeView::setupScreen() {
 
    radioButtonGroupParamsList.setRadioButtonSelectedHandler(cbRadioBtn);
}

But it has compile errror:

Severity Code Description Project File Line Suppression State

Error (active) E0434 a reference of type "touchgfx::GenericCallback<const touchgfx::AbstractButton &, void, void> &" (not const-qualified) cannot be initialized with a value of type "touchgfx::Callback<HomeView, const touchgfx::RadioButtonGroup<(uint16_t)6U> &, const touchgfx::ClickEvent, void>" Application C:\TouchGFXProjects\LagrevSimulation3\gui\src\home_screen\HomeView.cpp 41

Error C2664 'void touchgfx::RadioButtonGroup<6>::setRadioButtonSelectedHandler(touchgfx::GenericCallback<const touchgfx::AbstractButton &,void,void> &)': cannot convert argument 1 from 'touchgfx::Callback<HomeView,const touchgfx::RadioButtonGroup<6> &,const touchgfx::ClickEvent,void>' to 'touchgfx::GenericCallback<const touchgfx::AbstractButton &,void,void> &' Application c:\touchgfxprojects\lagrevsimulation3\gui\src\home_screen\homeview.cpp 41

If that is the case, then the code could be really messy, as I have a lot radio buttons and I don't want each of radio button has separate callback.

But I think it is possible to have a general callback for a group of radio button, since I see class RadioButtonGroup has public member function

voidsetRadioButtonSelectedHandler(GenericCallback< const AbstractButton & > & callback)

https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_radio_button_group#public-functions

But, it just I dont know how to use it right

BParh.1
Senior III

Ok finally I got it:

//in .hpp
touchgfx::Callback<MainView, const touchgfx::AbstractButton&> cbRadioBtnGroup;
void cbRadioBtnGroupHandler(const touchgfx::AbstractButton& src);
 
 
// in .cpp
MainView::MainView() :
    cbRadioBtnGroup(this, &MainView::cbRadioBtnGroupHandler) {
    radioButtonGroup.setRadioButtonSelectedHandler(cbRadioBtnGroup);
}
 
MainView::
void MainView::cbRadioBtnGroupHandler(const touchgfx::AbstractButton& src) {
    if(&src == &radioButton1) {
        // handle for radioButton1 selection
    }
    else if(&src == &radionButton2) {
       // handle for radioButton2 selection
   }
   ....
   else {}
 
 
}