array of butons

skywalker34

Member
Licensed User
Longtime User
I take the spirit of those few line in beginner's guide
I have used the designer to place my buttons so I don't initialize them
I keep button1 out of the array to compare result

The problem is that all my buttons defined in the array "Buttons" don't seem to work : in debug mode I place "stop" on the Buttons_click but I never reach it ???


here is the code :
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim Button1 As Button
Dim Button2 ,Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10, Button11,Button12 As Button
Dim Buttons() As Button


End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("test_button")
Buttons = Array As Button(Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10, Button11, Button12)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Buttons_Click
Dim btn As Button
btn = Sender
Log("Button " & btn.Tag & " clicked") 'write the line to LogCat
End Sub

Sub Button1_Click
Log("Button " & Button1.Tag & " clicked") 'write the line to LogCat
Log("I am here")

End Sub
 

stevel05

Expert
Licensed User
Longtime User
Have you set the event name in the designer to Buttons?
 
Upvote 0

skywalker34

Member
Licensed User
Longtime User
Have you set the event name in the designer to Buttons?

No, it was set to "button2" but as it was declare as array.....now this is working !

GREAT ! thank you very much !

maybe Can you tell me how to put picture on the button following external definition file ( not in the designer) is it the button.SetBackgroundImage()
in designer we can put image for pressed, dissabled and released so possibly 3 differents images...
 
Upvote 0

skywalker34

Member
Licensed User
Longtime User
OK I see....
in this case if I just need same picture on the button can I use
button.Background=LoadBitmap(File.DirAssets, "my_picture.png") ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You'd need to use
B4X:
 Button1.SetBackgroundImage(LoadBitmap(File.DirAssets, "my_picture.png"))
As Button1.Background requires an image of a different type. But you will lose the image changes on change of state that make a button look like a button.

Try it and see.
 
Upvote 0

skywalker34

Member
Licensed User
Longtime User

Great ! this is exactly what I need....many thanks

Now I need to change the picture on the fly for each of the 12 buttons when pressing "left" or "right" button, for a "page-definition" concept. It don't seem to much difficult as I already test files ready/writing.

This is my very first program with this dev tools and I am really surprised for the quality of this tools and really appreciate the active participation to the forum : this is a great help for beginner like me to avoid reading (understanding) the really big (but well made) "beginner's guide".
What is difficult is that this is not VB6 and not Windows....even if the reading and general syntax are similar, it has to be learned and discovered step by step.....
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…