Can't keep button on

Hi, my app has a screen with a series of buttons. They alternate their images between “on” and “off” when clicked and they are all “off” by default, but when I go to another screen and come back to the screen with the buttons they go back to false, as default.
I would like to know how I can keep a button on even when I change the screen and how I can allow only one button to be “on” at a time, turning the other buttons to “off” when another one is turned to “on”.

You could use tinydb to store buttons choices

Try this test aia

On_Off.aia (52.2 KB)

2 Likes

I see, but there are different “on” and “off” images for each of my buttons. How can I proceed in this case?

Give us your demo AIA… your view seems to different than Dora suggestion it seems… but Dora suggestion is best one.

1 Like

Just my suggestion is.

  1. Upload your images in asset
  2. Make a global variable with lists of buttons.
  3. And in screen init just set each button picture with for each item list block.
  4. Dora suggestion…

Got it??? Am I confused you?

Usually I will name the picture as the name of the component itself as button1.jpeg, button2.jpeg. etc… So it will be very convenient to assign picture for each button

1 Like

Why won’t you study provided test aia ?

1 Like

So for each button you use different pairs for on off, for example

button1 on1 off1
button2 on2 off2
etc…

and when button1 on show picture on1 and button2 show picture off2? Am I correct ?

1 Like

I am studying it, but I still didn’t understand yet.

asdfasf_copy (1).aia (1.7 MB)
This is the aia. The problem is in patterns screen. There are pattern buttons in the vertical arrangement. Their names are “Padrao_" and the corresponding pictures in assets are "Padrao_on" and "Padrao****_off”.

Let me check it

2 Likes

Have you tried like this…??

2 Likes

Try this

asdfasf_1.aia (1.7 MB)

2 Likes

It almost worked. The only problem is that when I click a button the “off” images are not from the respective button.

I know, I took pairs from assets. Otherwise provide a list showing with buttton has which on and which off icon

2 Likes

Another option is that you open the new screen without closing the one with the buttons. When you close the new screen, the user will be directed back to the previous screen and it will be shown with the same values and status as when the user left. Just keep in mind that the buttons screen will remain in memory and that at some point you need to close it.

1 Like

Sorry, I might have made some mistakes while uploading the images. Thank you so much for the help!!!

1 Like