So my first program is a basic soundboard. I'm unable to upload a zip file as it is too large but I'll post the code below.
My scrollview was working until I added a subroutine called Sub Init. This routine assigned a string to an array of button names (called btnName(i)). I've been told to "call" this routine before anything else in my Activity_Create sub. I'm not sure exactly where I'm going wrong and could use your help!
Here is my code:
My scrollview was working until I added a subroutine called Sub Init. This routine assigned a string to an array of button names (called btnName(i)). I've been told to "call" this routine before anything else in my Activity_Create sub. I'm not sure exactly where I'm going wrong and could use your help!
Here is my code:
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim mp As MediaPlayer
Dim svcButtons As ScrollView
Dim btnTest(13) As Button
Dim btnWidth = 150dip As Int
Dim btnHeight = 60dip As Int
Dim btnSpace As Int
Dim ImageView1 As ImageView
Dim btnName(13) As String
End Sub
'button text
Sub Init As String
btnName(0) = "fun problem"
btnName(1) = "stupid #"
btnName(2) = "Jesus God"
btnName(3) = "finish"
btnName(4) = "aliens"
btnName(5) = "wall"
btnName(6) = "heart"
btnName(7) = "little activity"
btnName(8) = "hit that"
btnName(9) = "idiot"
btnName(10) = "mexicans"
btnName(11) = "political bs"
btnName(12) = "wacko"
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
mp.Initialize
'Activity.LoadLayout("first")
ImageView1.Initialize("")
svcButtons.Initialize(100)
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"bob.jpg")
Activity.AddView(ImageView1, 30dip, 10dip, 260dip, 170dip)
Activity.AddView(svcButtons, 0, 0, 100%x, 100%y)
Dim i As Int
btnSpace = btnHeight / 2 + 1dip
For i = 0 To 12
If i Mod 2=0 Then
btnTest(i).Initialize("btnTest")
svcButtons.Panel.AddView(btnTest(i), 10dip, 190dip + i * btnSpace, btnWidth, btnHeight)
Else
btnTest(i).Initialize("btnTest")
svcButtons.Panel.AddView(btnTest(i), 160dip, 190dip + (i-1) * btnSpace, btnWidth, btnHeight)
End If
btnTest(i).Text = btnName(i)
btnTest(i).Tag = i
Next
svcButtons.Panel.Height = 10dip + i * btnSpace
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'Sound Clips
Sub btnTest_Click
Dim btn As Button
btn = Sender
mp.Load(File.DirAssets, btn.Tag & ".wav")
mp.Play
End Sub