2021-02-17 9:11 AM
Hi,
I have 3 radio-buttons in a custom container which is present on several screens.
I would like the radio-buttons to keep their states between when switching screens.
I have the radio-buttons states reported to the model every time a button is pressed and when the screen changes, the new active view fetches the radio-button state.
However, I do not see a function to update a radio-button state without triggering the button action.
Is there such a function?
2021-02-18 7:12 AM
Why you define callbacks in base code, when i create screen with radio my code is
/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <touchgfx/Color.hpp>
#include "BitmapDatabase.hpp"
Screen1ViewBase::Screen1ViewBase()
{
__background.setPosition(0, 0, 800, 480);
__background.setColor(touchgfx::Color::getColorFrom24BitRGB(0, 0, 0));
toggleButton1.setXY(336, 193);
toggleButton1.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_TOGGLEBARS_TOGGLE_ROUND_LARGE_BUTTON_OFF_ID), touchgfx::Bitmap(BITMAP_BLUE_TOGGLEBARS_TOGGLE_ROUND_LARGE_BUTTON_ON_ID));
radioButton1.setXY(356, 43);
radioButton1.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_INACTIVE_ID), touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_PRESSED_ID), touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_ACTIVE_ID), touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_NORMAL_ID));
radioButton1.setSelected(false);
radioButton1.setDeselectionEnabled(false);
radioButton2.setXY(356, 104);
radioButton2.setBitmaps(touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_INACTIVE_ID), touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_PRESSED_ID), touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_ACTIVE_ID), touchgfx::Bitmap(BITMAP_BLUE_CHECK_BUTTONS_CHECK_MARK_NORMAL_ID));
radioButton2.setSelected(true);
radioButton2.setDeselectionEnabled(false);
add(__background);
add(toggleButton1);
add(radioButton1);
add(radioButton2);
radioButtonGroup1.add(radioButton1);
radioButtonGroup1.add(radioButton2);
}
void Screen1ViewBase::setupScreen()
{
}no callbacks here...
place this in view setup code after change selected states
radioButtonGroup.setRadioButtonSelectedHandler(radioButtonSelectedCallback);
2021-02-18 7:29 AM
The callback defined in the base file has been generated using TouchGFX designer.
The code I have added is in the MainView.cpp.
2021-02-18 7:33 AM
As i write when you plan change state against designer states, without call callback, then you can dont generate callbacks to base file, and do it yourself in setup code ...
maybe too is possible redefine callback to null , set new group state and reaply original callback, but this i dont try.
2025-02-10 6:18 AM - edited 2025-02-10 6:19 AM
Hi all,
I have the same problem (I'm using 4.24.0 version):
I have a lot of screens with radiobutton, And at at startup I need to change the selections due to user configuration.
But everytime I call "setSelected" the relative action is called and this trigger wrong behaviour on my code
I suggest in the next touchgfx release to insert a method similar to "forcestate" to upgrade the radiobutton state without generate action.
I would like to avoid to delete the callback in realtime and after change the status re-enabled them.
2026-01-29 6:50 AM
Hello,
@MPast.1, you are the latest comment in this thread about the double firing of the callback function, did you manage to solve this issue?
in my application I'm using the setSelected function of the radio button and not of the radio button group, I manage to call the callback function only once as i wanted but since it wasn't the setSeclted function of the radio button group it didn't felt right. if you solved this, it would be kind of you to share the solution.
Thank you and best regards
2026-01-29 12:36 PM
2026-02-01 11:19 PM
Hi @MPast.1
I believe by saying "setSelected", you mean the function in the radio button group, because that one fires the callback twice, but if you try to use the "setSelected" of the radio button (not the group), that will fire the callback only once.
and if you set a counter depends on how many things you have to configure and when the counter reached that number then you can send the UART, no timer needed here, well, this depends on your architecture for sure. and this didn't solve the original problem,
this is the "setSelected" function of the RadioButton group
virtual void setSelected(RadioButton& radioButton)
{
radioButton.setSelected(true);
radioButtonClickedHandler(radioButton);
}as you can see, it already call the "setSelected" function of the radio button itself, and also call the click handler that will set the select option to other radio button to false and then run a call back, that call back will also fire the same "setSelected" function of radio button that have been fired, so, this is why it fires twice.
virtual void radioButtonClickedHandler(const AbstractButton& radioButton)
{
// Deselect other radio buttons
for (uint16_t i = 0; i < size; i++)
{
if (radioButtons[i] != &radioButton)
{
if (radioButtons[i]->getSelected())
{
radioButtons[i]->setSelected(false);
}
}
}
if (radioButtonSelectedCallback && radioButtonSelectedCallback->isValid())
{
radioButtonSelectedCallback->execute(radioButton);
}
}
I don't know what is the correct initialization i should do to make it fire only once. not sure if this is a bug or we shouldn't use the setSelect of radio button group at all. in the end, i just used the setSelect of each radio button for my dynamic configuration.