Hi !
As a total B4a beguinner I apologize for stupid questions I will have or that are already answered in the guides I try to digest.
I coded my first training thing today it's a simple array of buttons that can have 3 states represented by 3 differents images.
It works, but when running it on my galaxy notes 2 tab it is somehow slow and not very responsive.
Can someone look at the code and tell me what's I'm doing wrong ?
I can't believe the galaxy tab can't handle displaying 120 buttons and updating the background of one of them when clicked.
Or maybe it is still interpreted on my galaxy tab ?
Thanks in advance for any help you can provide.
Also if someone can tell me why when I change the orientation of my tablet my state array is reseted
As a total B4a beguinner I apologize for stupid questions I will have or that are already answered in the guides I try to digest.
I coded my first training thing today it's a simple array of buttons that can have 3 states represented by 3 differents images.
It works, but when running it on my galaxy notes 2 tab it is somehow slow and not very responsive.
Can someone look at the code and tell me what's I'm doing wrong ?
I can't believe the galaxy tab can't handle displaying 120 buttons and updating the background of one of them when clicked.
Or maybe it is still interpreted on my galaxy tab ?
Thanks in advance for any help you can provide.
Also if someone can tell me why when I change the orientation of my tablet my state array is reseted
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: MineSweeper
#VersionCode: 0
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
Sub Process_Globals
Dim sizeX As Int
Dim sizeY As Int
sizeX = 10
sizeY = 12
Dim BlockX As Int
Dim BlockY As Int
BlockX=60
BlockY=60
End Sub
Sub Globals
Dim buttons(sizeX,sizeY) As Button
Dim imgon, imgoff, imgnone As Bitmap
Dim state(sizeX,sizeY) As Int
End Sub
Sub UpdateButtonBackground (x As Int,y As Int)
If state(x,y) = 0 Then buttons(x,y).SetBackgroundImage(imgoff)
If state(x,y) = 1 Then buttons(x,y).SetBackgroundImage(imgon)
If state(x,y) = 2 Then buttons(x,y).SetBackgroundImage(imgnone)
End Sub
Sub Activity_Create(FirstTime As Boolean)
imgoff.Initialize(File.DirAssets, "0.png")
imgon.Initialize(File.DirAssets, "1.png")
imgnone.Initialize(File.DirAssets, "2.png")
For x=0 To sizeX-1
For y=0 To sizeY-1
buttons(x,y).Initialize("ButtonEvent")
buttons(x,y).Tag=y*sizeY+x
If FirstTime = True Then state(x,y)=0
Activity.AddView(buttons(x,y), 100+BlockX*x, 100+BlockY*y, BlockX, BlockY)
UpdateButtonBackground(x,y)
Next
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ButtonEvent_Click
Dim btn As Button
btn = Sender
Dim x,y As Int
y=Floor(btn.Tag/sizeY)
x=btn.Tag-y*sizeY
state(x,y)=state(x,y)+1
If state(x,y)>2 Then state(x,y)=0
UpdateButtonBackground(x,y)
Activity.Title = state(x,y)
End Sub