2024-11-22 09:19 AM
I have two buttons on Screen1. Both interactions change screen to Screen2.
Can I determine which button was pressed when in Screen2View::setup?
Or do I need to use a separate virtual functions and then create a variable setting the button called?
Solved! Go to Solution.
2024-11-26 08:46 AM - edited 2024-11-26 08:47 AM
Hello @FJB2069 ,
Here is a simple example with 5 buttons and interactions calling a same action that takes a value (from 1 to 5 based on the button pressed).
Note that you still have to create one interaction se choose the value you want to send when each button is clicked (for instance the buttons could be to add a product to a shopping cart in which case it should return the product ID).
Also, for such a simple example, it is even easier to directly print in the interaction created but I assume your final application is more complex.
Regards,
2024-11-22 10:16 AM
Go create a widget or a screen with many flex buttons.
In the base class you will see how the source of the button are detected.
void *::flexButtonCallbackHandler(const touchgfx::AbstractButtonContainer& src)
2024-11-22 11:45 AM
I see the flexButtonCallback in Screen1ViewBase.cpp.
I am trying to break on this section to follow when I press button, but only breaks when I return to screen, not button press.
Sorry, I am not familiar with how to use this callback or handler, any help would be appreciated!
2024-11-22 11:48 AM
wait, I see in the handler it shows each button..... I will try to make a variable that saves which button was pressed so that after the data is input in screen2 I can return the data the correct flexbutton text area.
2024-11-22 04:09 PM
How can I save which button was pressed in the Model before the screen is changed?
In the base view it shows which button was pressed, but how can I save that button into a variable using MVP ( I assume this would be the correct way) before the screen is changed. then be able to access that variable when I return to screen 1?
void Screen1ViewBase::flexButtonCallbackHandler(const touchgfx::AbstractButtonContainer& src)
{
if (&src== &flexButtonNum10s)
{
//Interaction1
//When flexButtonNum10s clicked change screen to Screen2
//Go to Screen2 with no screen transition
application().gotoScreen2ScreenNoTransition();
}
if (&src== &flexButtonNum1s)
{
//Interaction2
//When flexButtonNum1s clicked change screen to Screen2
//Go to Screen2 with no screen transition
application().gotoScreen2ScreenNoTransition();
}
}
2024-11-25 05:26 AM
Hello @FJB2069 ,
Regarding your last message, it look like you have created 2 interactions :
This creates functions in the base file that cannot be modified by hand.
So instead, you could modify your 2 interactions so that the action is either "call new virtual function" or create an action (with a value of type int8) and call that action while specifying the button number. Then, on those 2 interactions, select "can trigger another interaction" and create 2 new interactions where the trigger is "another interaction is finished" and the action is to change to screen 2.
This way, you are able to call extra code (through the virtual function or through the action) before the screen changes.
Regards,
2024-11-25 01:13 PM
Are you referring to creating a custom container with an action1 and then creating an interaction action1 is called int8_t? then creating an action to change screen or a virtual function, then trigger another action...... I getting confused just writing this!
I understand the concept, but not sure how to implement it. Can you be more specific or is there a tutorial on this?
2024-11-26 08:46 AM - edited 2024-11-26 08:47 AM
Hello @FJB2069 ,
Here is a simple example with 5 buttons and interactions calling a same action that takes a value (from 1 to 5 based on the button pressed).
Note that you still have to create one interaction se choose the value you want to send when each button is clicked (for instance the buttons could be to add a product to a shopping cart in which case it should return the product ID).
Also, for such a simple example, it is even easier to directly print in the interaction created but I assume your final application is more complex.
Regards,
2024-12-05 02:48 PM
Thank you.
2024-12-06 01:28 AM
Hello @FJB2069 ,
My pleasure.
Were you able to solve your issue with that example? If so, I invite you to select it as "best answer".
Regards,