Italian Array di moltissimi pulsanti

AlpVir

Well-Known Member
Licensed User
Longtime User
Per creare molti pulsanti gestibili da una unica Sub BotMappa_Click utilizzo abitualmente il seguente codice

B4X:
Dim BotMappa(13)  As Button
Dim b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 As Button

BotMappa = Array As Button (b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13)
for i=0 to 12
    BotMappa(i).Initialize ("BotMappa")
    Activity.addview (BotMappa(i), ecc ecc ecc
next

Ma, ed è questa la domanda, se i pulsanti sono (ad esempio) 200 devo scrivere
b14,b15,b16,b17,b18,b19 .... fino a 200 ? Non c'è qualche scorciatoia ?

Grazie per l'attenzione.
 

klaus

Expert
Licensed User
Longtime User
You don't need
Dim b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 AsButton
BotMappa = ArrayAsButton (b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13)


Just
B4X:
Dim BotMappa(13)  As Button

For i=0 to 12
    BotMappa(i).Initialize ("BotMappa")
    Activity.AddView (BotMappa(i), ecc ecc ecc
    BotMappa(i).Tag = i
Next
'
'
Sub BotMappa_Click
    Dim btn As Button
    Dim Index As Int

    btn = Sender      ' button that raised the ecent
    Index = btn.Tag  ' index of the button that raised the event
    '  your code
End Sub
 

AlpVir

Well-Known Member
Licensed User
Longtime User
Intuivo che ci dovesse essere un modo migliore per risolvere la questione, ma non riuscivo a trovarlo.
Grazie a tutti.
 
Top