Sub Check_Conditon as Boolean
'Check some conditions and return true/false
End Sub
Sub Do_Task
Do while Check_Condition
'Do some tasks which may change the "Check_Condition" output
'Also do some animations
Loop
End Sub
My problem is, when the Do loop is run the 1st time, everything is ok. But then when it loops into the 2nd time, all my animations from the 1st loop is still running and hence being restarted, or run wrongly. How can I solve this?
How are you implementing the animations? If you are using the Animation library then you can handle the Completed event.
If you are using SetLayoutAnimated then you need to create a timer and set its interval to be the same as the animation duration.
B4X:
Sub Process_Globals
Private timer1 As Timer
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim b As Button
b.Initialize("")
b.Text = "Sdf"
Activity.AddView(b, 10dip, 10dip, 100dip, 100dip)
b.SetLayoutAnimated(1000, 200dip, 200dip, 40dip, 40dip)
timer1.Initialize("timer1", 1000)
timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
Log("Animation completed!")
timer1.Enabled = False
End Sub
I'm using nineoldandroids lib. In my sub Do_task, I have a (8,16) array of label. And base on some conditions I will set the animation to some of them. There are 2 kinds of animations, 1 is to scale the label, the others is to move the label. When the code run, it will check the label array for any label needed to be scaled, if have then do the scaling animation, then it will check again for any label needed to be moved and do the moving animation.