Italian index bottone

saslvovc

Member
Licensed User
Longtime User
Ciao
ho una seri di 9 bottoni
Come faccio a ricavare Index Bottone Cliccato.
 
Last edited:

sirjo66

Well-Known Member
Licensed User
Longtime User
Per ogni bottone metti la proprietà Tag diversa (cioè gli assegni un numero), poi nell'evento Click esegui:
B4X:
Dim btn As Button = Sender
Dim index as Int = btn.Tag
Log(index)

Sergio
 

saslvovc

Member
Licensed User
Longtime User
Scusate ma ho posto male la domanda
voglio eseguire questa routine presa da vb6

B4X:
Private Sub btnnum_Click(Index As Integer)
Dim swap As String

If Index < 9 Then
      If btnnum(Index + 1).BackColor = vbWhite Then
      swap =btnnum(Index).Caption
      btnnum(Index).Caption = ""
      btnnum(Index).BackColor = vbWhite
      btnnum(Index + 1).Caption = swap
      btnnum(Index + 1).BackColor = vbBlue
 End If
End If
End Sub
 

udg

Expert
Licensed User
Longtime User
La risposta di Sergio resta valida.
Per avere un codice molto simile a quello indicato dovrai dimensionare ed inizializzare un array di buttons e poi nell'evento comune usare il codice di Sergio per sapere quale dei 9 tasti sia stato premuto..
Qualcosa del genere:
B4X:
Dim btnnum(8) as button
for j= 0 to 8
  btnnum(j).Initialize("btnum")
  btnnum(j).tag= j
  panel (or activity..) addview(btnum(j),...)
next

sub btnum_Click
  dim swap as string
  Dim btn AsButton = Sender
  Dim index as Int = btn.Tag
  If btnnum(Index + 1).BackColor = colors.White Then
    swap =btnnum(Index).Caption
    btnnum(Index).Caption = ""
    btnnum(Index).BackColor = colors.White
    btnnum(Index + 1).Caption = swap
    btnnum(Index + 1).BackColor = colors.Blue
end if
Ovviamente quello che precede non è codice già funzionante, ma ti serve per avere un'idea di cosa fare.
 
Top