Android Question How to animate background color for label click?

Diceman

Active Member
Licensed User
Is this the correct way to animate the background color when the user clicks on a label?

B4X:
Sub Label1_Click
    If Sender Is Label Then
        Private locLabel As Label=Sender
        locLabel.SetColorAnimated(200, Colors.Transparent,   Colors.Red)
        Sleep(200)
        locLabel.SetColorAnimated(200, Colors.Red, Colors.Transparent)
    End If
End Sub
I only ask because I had to put in the Sleep(200) otherwise the 2nd SetColorAnimated executes right away.
I could create a formal animation rtn to do it, but I wanted to keep it simple.

TIA
 

LucaMs

Expert
Licensed User
You answered yourself!


Rather, the handling of the event and the Label is "anomalous", although I know it's an example.

If the event routine can be triggered by more than one View and of different types, its name should not be the one of a specific Label and should make sense.

If, on the other hand, it is triggered only by Label1, it is not necessary to use Sender but directly Label1 declared in the Activity.
 

Diceman

Active Member
Licensed User
You answered yourself!


Rather, the handling of the event and the Label is "anomalous", although I know it's an example.

If the event routine can be triggered by more than one View and of different types, its name should not be the one of a specific Label and should make sense.

If, on the other hand, it is triggered only by Label1, it is not necessary to use Sender but directly Label1 declared in the Activity.
I should have mentioned that a dozen labels would be calling this rtn, which is why I am using Sender. I'm using animation because without it the user won't know if clicking on a label has an affect or not.

The reason for my post was because I was concerned whether the Sleep(200) was necessary or if there was a different way to flash the label when clicked. I know some B4A purists don't like to use Sleep() and I thought there was a better way to handle it.
 

Diceman

Active Member
Licensed User
No @Diceman, I've just read your post again. You do not need the if statement. Just declare locLabel = sender and take it from there...
Yeah, but I'm a belt and suspenders type of guy. Coming from a Delphi background I always check the data type before assigning it to a class. This prevents unintended exceptions. Maybe some day I will be "reckless" and assume the calling rtn always knows that it is doing, but not today. :D
 
Top