I have this code, there are several buttons with images, the idea is to press and change the image, to the selected image and when I press again to return to the main image.
Sub Activity_Create(FirstTime As Boolean)
Dim i As Int
Dim pos As Int
scvMain.Initialize(400)
Activity.AddView(scvMain, 0, 0, 100%x,100%y)
Activity.LoadLayout("ScrollViewNLayouts")
Dim pnltest As Panel
Dim lblTest As Label
Dim btnTest As Button
Dim edtTest As EditText
Dim pnl As Panel
Dim sld As StateListDrawable
Dim bmpTeam As BitmapDrawable
Dim bmpSel As BitmapDrawable
Dim bmpBackground As Bitmap
Dim bmdBackground As BitmapDrawable
Dim etiqueta As Label
Dim boton2 As Button
'Dim TipoBus As Int
Dim Bus() As Int
Dim Posicion() As Int
Dim Buttons(64) As Button
TipoBus=25
PanelNb=6
' Asiento 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Bus = Array As Int(1 , 95, 315,1 ,95, 315,1 , 95, 315,1 , 95, 315, 1 , 95, 315, 1 , 95, 315, 1 , 95, 315, 1 , 95, 315, 1)
Posicion = Array As Int(1,1,1 ,1, 100, 100,100,190,190,190, 280, 280, 280, 370, 370, 370, 460, 460, 460, 550, 550, 550, 640, 640,640,730,730,730,820,820,820,910,910)
bmpBackground.Initialize(File.DirAssets,"bus.png")
bmdBackground.Initialize(bmpBackground)
Activity.Background = bmdBackground
For i=1 To TipoBus
If pos <> Posicion(i) Then
'salto de linea
pnltest.Initialize("pnlTest")
scvMain.Panel.AddView(pnltest,0,Posicion(i),100%x,PanelHeight)
pnltest.Tag=i
pos=Posicion(i)
End If
' boton con imagen
btnTest.Initialize("btnTest")
bmpTeam.Initialize(LoadBitmap(File.DirAssets,"asiento.png"))
bmpSel.Initialize(LoadBitmap(File.DirAssets,"asiento_sel.png"))
sld.Initialize
sld.AddState(sld.State_Disabled, bmpTeam )
sld.AddState(sld.State_Pressed, bmpSel )
btnTest.Background = sld
btnTest.Text=i
btnTest.Tag=i
btnTest.TextColor=Colors.Black
btnTest.TextSize=18
pnltest.AddView(btnTest,Bus(i-1)+2%x, 1dip, 70dip, 70dip)
Buttons(i) = btnTest '2dip
Next
scvMain.Panel.Height=PanelNb*PanelHeight
'pnl.Height = lstChecks.Size * height
'Activity.AddMenuItem("Display checked", "mnuChecked")
End Sub
[/url][/IMG]
Sub Activity_Create(FirstTime As Boolean)
Dim i As Int
Dim pos As Int
scvMain.Initialize(400)
Activity.AddView(scvMain, 0, 0, 100%x,100%y)
Activity.LoadLayout("ScrollViewNLayouts")
Dim pnltest As Panel
Dim lblTest As Label
Dim btnTest As Button
Dim edtTest As EditText
Dim pnl As Panel
Dim sld As StateListDrawable
Dim bmpTeam As BitmapDrawable
Dim bmpSel As BitmapDrawable
Dim bmpBackground As Bitmap
Dim bmdBackground As BitmapDrawable
Dim etiqueta As Label
Dim boton2 As Button
'Dim TipoBus As Int
Dim Bus() As Int
Dim Posicion() As Int
Dim Buttons(64) As Button
TipoBus=25
PanelNb=6
' Asiento 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Bus = Array As Int(1 , 95, 315,1 ,95, 315,1 , 95, 315,1 , 95, 315, 1 , 95, 315, 1 , 95, 315, 1 , 95, 315, 1 , 95, 315, 1)
Posicion = Array As Int(1,1,1 ,1, 100, 100,100,190,190,190, 280, 280, 280, 370, 370, 370, 460, 460, 460, 550, 550, 550, 640, 640,640,730,730,730,820,820,820,910,910)
bmpBackground.Initialize(File.DirAssets,"bus.png")
bmdBackground.Initialize(bmpBackground)
Activity.Background = bmdBackground
For i=1 To TipoBus
If pos <> Posicion(i) Then
'salto de linea
pnltest.Initialize("pnlTest")
scvMain.Panel.AddView(pnltest,0,Posicion(i),100%x,PanelHeight)
pnltest.Tag=i
pos=Posicion(i)
End If
' boton con imagen
btnTest.Initialize("btnTest")
bmpTeam.Initialize(LoadBitmap(File.DirAssets,"asiento.png"))
bmpSel.Initialize(LoadBitmap(File.DirAssets,"asiento_sel.png"))
sld.Initialize
sld.AddState(sld.State_Disabled, bmpTeam )
sld.AddState(sld.State_Pressed, bmpSel )
btnTest.Background = sld
btnTest.Text=i
btnTest.Tag=i
btnTest.TextColor=Colors.Black
btnTest.TextSize=18
pnltest.AddView(btnTest,Bus(i-1)+2%x, 1dip, 70dip, 70dip)
Buttons(i) = btnTest '2dip
Next
scvMain.Panel.Height=PanelNb*PanelHeight
'pnl.Height = lstChecks.Size * height
'Activity.AddMenuItem("Display checked", "mnuChecked")
End Sub