Android Question Label SetVisibleAnimated

AR_B4X

Member
Licensed User
Hi there,
So all I want here is a button. It should display Hello when odd number of clicks and nothing when even number of clicks.

B4X:
Sub Globals
    Dim Label1 As Label
    Dim Button1 As Button
    Dim click As Int = 0
End Sub

Sub Button1_Click
    click = click + 1
  
    If click = 2 Then
        Label1.SetVisibleAnimated("1000", False)
        click = 0
    Else
        Label1.Text = "Hello"
        Label1.Visible = True
    End If
  
End Sub

1st click - Displays Hello
2nd click - Hides Hello
3rd click - Goes in the Else part (which is correct) but even after executing
Label1.Text = "Hello" and Label1.Visible = True, it doesn't display Hello.
I am just curious if I need to do something after using SetVisibleAnimated?
Thank you

Additional question: Can you please tell me what internal process happens when SetVisibleAnimated function is executed? Specifically I would like to know what happens when a button is clicked several times between 0 and 1000 ms when SetVisibleAnimated function is executed.
 

mangojack

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

AR_B4X

Member
Licensed User
Thank you very much!
That one worked.

In a different scenario, I have three buttons with corresponding three labels over them.
Each label needs to appear/disappear on odd and even of its underlying button click.

Whats happening is that when I randomly click across these buttons very quickly - say 2 clicks in less than 1000ms, the program doesn't seem to work correctly. That is, I noticed that even with 2 quick clicks it doesn't appear.

So I would like to know is it possible to abort the SetVisibleAnimated before its duration?
That is I want to make the label visible before the fading animation ended?

Thank you
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
So I would like to know is it possible to abort the SetVisibleAnimated before its duration?
That is I want to make the label visible before the fading animation ended?
Thank you

The link at end of my last post now works ... Please Have a Read ! it covered similar question other day.

You could probly do more seriuos stuff with animation lib ... but have never used.

A bit rough. but try this .. again not working 100% .. but something to work on.
B4X:
Sub Globals
   Dim btn(3) As Button
   Dim lbl(3) As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)

  For i = 0 To btn.Length -1
    btn(i).Initialize("Button")
    btn(i).Tag = i
    btn(i).Text = ""
    Activity.AddView(btn(i),0,i*90dip,240dip,80dip)

     bl(i).Initialize("")
     lbl(i).Text = "Hello"
     lbl(i).Tag = i
     lbl(i).TextSize = 34
     lbl(i).Gravity = Gravity.CENTER_HORIZONTAL
      Activity.AddView(lbl(i),20dip,btn(i).Top + 15dip,200dip,60dip)
  Next

End Sub

Sub Button_Click

   Dim b As Button = Sender
   Dim i As Int = b.Tag
     If lbl(i).Visible = True Then
       lbl(i).SetVisibleAnimated (1000, False) 'for test replace with lbl(i).Visible = False
     Else
       lbl(i).SetVisibleAnimated(1000, True)   'for test replace with lbl(i).Visible = True
   End If

End Sub

Edit .. I don't think you can 'Interrupt' the animation .. certainly in this example because the current button click can only work on the 'Current visible status of Label.
ie. if the button click is quicker than 1 sec it will only call the same code again.
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
This might interest you .. Calling Label Animation ...

I have re-zipped an example as the final working code posted by @Erel did not include layout etc.. Remember to check/tick Animation lib.
 

Attachments

  • TestAnimation.zip
    8.3 KB · Views: 308
Upvote 0

BaGRoS

Active Member
Licensed User
Longtime User
I have used
B4X:
ImageView1.SetVisibleAnimated(10000, True)
and ImageView1 is visible, but veeeery fast, not 10 second...
Why?
 
Upvote 0
Top