I create 16 buttons programmatically and I want for all the buttons to be invisible when any of the buttons are clicked. The code I use to create the buttons are below.
B4X:
Dim x, y As Int
Dim width, offsetX, offsetY As Int
width = 37dip
offsetX = 20'(100%x - width * sw - 10dip * 2 ) / 2
offsetY = 20'(100%y - width * sw - 10dip * 2) / 2
Dim Buttons(8, 2) As Button
For x = 0 To sw
For y = 0 To 1
Dim b As Button
b.Initialize("button") 'All buttons share the same event sub
Activity.AddView(b,offsetX + x * (width + 3dip), offsetY + y * (width + 3dip), width, width)
Buttons(x, y) = b 'store a reference to this view
Next
Next
Hey Erel, I used your code but it is only making one button invisible. The 9th button. So it is 2 rows with 8 buttons each row so it is the first button on the second row. SW is equal to 7 which counting zero that is 8. Any ideas?
LOL. Thanks. That was the problem. I just wish I was smart enough to figure it out. LOL. I knew the 0,1 didn't look right. But that was as far as I got. LOL
Sorry for my dull question, I don´t understand that. How can I make the button "btnSave" unvisible??
Buttons(btnSave).Visible = False? Doesn´t work (I defined "Buttons" as Button).
"btnSave.Visible = False" doesn´t work neither.
Hello Klaus!
Yes, I did it exactly this way and the code stops at that line (btnSave.Visible = False)!??
I have only one button. Do I need a special library?
best regards
You need to show more code to help you.
Without knowing what you have done it's difficult to help
Is the button defined in a layout file, or is it defined in the code etc ?
You need to show more code to help you.
Without knowing what you have done it's difficult to help
Is the button defined in a layout file, or is it defined in the code etc ?
The button "btnSave" is defined in the layout. The relevant code is only:
B4X:
Sub Globals
Dim btnSave As Button
....
End Sub
Sub Activity_Create(FirstTime As Boolean)
btnSave.Visible = False
.....
The debugger runs without problems. But when I run the app on the phone I get the error: "Program paused on line 43..."
I don´t know what else could be relevant.
The button "btnSave" is defined in the layout. The relevant code is only:
B4X:
Sub Globals
Dim btnSave As Button
....
End Sub
Sub Activity_Create(FirstTime As Boolean)
btnSave.Visible = False
.....
The debugger runs without problems. But when I run the app on the phone I get the error: "Program paused on line 43..."
I don´t know what else could be relevant.