iOS Question Totally stuck need help with code.

John Sturt

Active Member
Licensed User
Longtime User
Hello
I have posted the following code
to demonstrate the problem i am having.

The code will generate a page of labels and when clicked will
change colour.

When a label is long clicked the code goes into a 3 second loop
which re-colours the labels at random and then displays the whole screen at once.

The effect i am looking for is one that shows the screen
after each single change.

I have tried many possible solutions to this and none of them work.

Any ideas on which route to take?

Thanks in advance.

B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   
   Dim Grid(10,10) As Int
   Dim GridLabel (10*10) As Label
   Dim Xsize,Ysize As Float
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   NavControl.ShowPage(Page1)
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   Xsize = 100%x / 10
   Ysize = 100%y / 10
   
   Dim Index As Int
   
   For x=0 To 10-1
   For y=0 To 10-1
     Index = x+(y*9)
     
     GridLabel(Index).Initialize ("LabelEvent")
     GridLabel(Index).Text = "Label "&Index
     GridLabel(Index).Tag = Index
     Page1.RootPanel.AddView (GridLabel(Index),x*Xsize,y*Ysize,Xsize,Ysize)
   Next
   Next
End Sub

Private Sub Application_Background
   
End Sub


Sub LabelEvent_click
   Dim L As Label
   l = Sender
   Dim Cellx,Celly As Int
   Cellx = GridLabel(L.tag).Left  / Xsize
   Celly = GridLabel(L.tag).Top / Ysize
   Grid(Cellx,Celly) = Colors.RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))
   UpdateCellAt(Cellx,Celly)
End Sub

Sub UpdateCellAt(Upx As Int,Upy As Int)
   GridLabel(Upx+(Upy*9)).Color = Grid(Upx,Upy)
End Sub

Sub labelEvent_longclick
   Dim now As Long = DateTime.Now
   Dim Rx,Ry As Int
   Do While DateTime.now < now+3000
     Rx = Rnd(0,10)
     Ry = Rnd(0,10)
     Grid(Rx,Ry) = Colors.RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))
     UpdateCellAt(Rx,Ry)
   Loop
End Sub
 

sorex

Expert
Licensed User
Longtime User
you better use timers, the app might not be able to update the screen due to that freeze loop.
 
Upvote 0
Top