Multi state button / image

Sithemon

New Member
Hi everybody

Im a total newbie to this software and have the following question.

Is it possible to create a clickable button / image that cycles through 5 colour states.

Red with the text "F"
Green with the text "S"
Yellow with the Text "C"
Blue with the text "D"
Grey with the text "-"

Im a guitar teacher and i want to make an app for when im testing my students for there grades. (Started, Completed, Discrepancy and Fail). It beats a piece of paper :)

I have a screen that will have around 30 to 40 instances of this.

If anyone can point me in the right direction i would be extremely grateful

Cheers

Si
 

lagore

Active Member
Licensed User
Longtime User
That is an easy one to do, in the designer create your layout with your buttons, give them all the same 'event name' (in my example I used Grade)
B4X:
Sub Grade_Click
   Dim b As Button
   b = Sender
   b.tag = b.tag + 1
   If b.tag > 5 Then b.tag = 1
   Select b.tag
      Case 1
         ButtonBackGrd(Colors.Red, "F")
      Case 2
         ButtonBackGrd(Colors.Green, "S")
      Case 3
         ButtonBackGrd(Colors.Yellow, "C")
      Case 4
         ButtonBackGrd(Colors.Blue, "D")
      Case 5
         ButtonBackGrd(Colors.Gray, "-")
   End Select
   
End Sub

Sub ButtonBackGrd(bc As Int, txt As String)
   Button1.Color = bc
   Button1.Text = txt
End Sub
in the designer you can set a default state for the buttons and set the tags to '0'. the first time you click a button the tag will be increased to 1, colour set to 'Red' and text to "F". (The exact same can be achieved with panels). You may prefer to use the 'LongClick' event instead of click. You will need to save the state of the buttons (next process) check out 'StateManager' or you could create a MAP with the button name as key and tag as value, on activity pause iterate thru all of the buttons and save the MAP then on resume if the MAP file exists load it and reset all of the buttons.
 
Upvote 0
Top