#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
Dim cont As Int
cont = 0
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private clvGrid As CustomListView150
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("lytGrid")
MakeGrid
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub MakeGrid
Dim List1 As List
List1.Initialize
List1.Add("Pizza margherita")
List1.Add("Pizza wurstel")
List1.Add("Pizza sarda")
List1.Add("Pizza olive")
List1.Add("Pizza rossa")
List1.Add("Pizza frutti di mare")
List1.Add("Pizzza svedese")
List1.Add("Pizza salsiccia secca")
List1.Add("Pizza rossa")
List1.Add("Pizza 10")
List1.Add("Pizzza 11")
List1.Add("Pizza 12")
List1.Add("Pizza 13")
List1.Add("Pizzza 14")
List1.Add("Pizza 15")
List1.Add("Pizza 16")
List1.Add("Pizzza 17")
List1.Add("Pizza 18")
Dim cellheight As Int = (clvGrid.asview.width - 4dip) /3
'Repeat for as many records you have to display in the CLV. Note: I set it to 5 just to fill a bit the CLV.
For indice_lista = 0 To List1.Size-1
Dim row As Int = indice_lista / 3
Dim cell As Int = (indice_lista Mod 3 )
'load the 3 panels layout to fill each clv's row.
Dim rowpnl As Panel
If cell = 0 Then
rowpnl.Initialize("")
rowpnl.LoadLayout("lytGridRow")
Else
rowpnl = clvGrid.getPanel(row)
End If
Dim bckpnl As Panel = rowpnl.GetView(0) 'layout has a backpanel as itd foundation
'load the 3 panels layout to fill each clv's row.
Dim rowpnl As Panel
rowpnl.Initialize("")
rowpnl.LoadLayout("lytGridRow")
Dim bckpnl As Panel = rowpnl.GetView(0) 'layout has a backpanel as itd foundation
'Left cell panel
Log ("cell : " & cell)
Dim cellpnl As Panel = bckpnl.getview(cell) 'left cell
cellpnl.LoadLayout("lytCell")
'we should load DB data in cellpnl's items, but here we don't so nothing is shown
Dim bckp As Panel = cellpnl.GetView(0)
Dim image As ImageView = bckp.GetView(0) 'image view
image.Bitmap = LoadBitmapSample(File.DirAssets,"pizza.png",bckp.Width, bckp.Height/2)
Dim title As Label = bckp.GetView(1) 'title
title.Text = List1.Get(indice_lista)
Dim Stitle As Label = bckp.GetView(2) 'subtitle
Stitle.Text = "mozarella"
'Dim Prezzo As Label = bckp.GetView(3) 'nuova label posta dopo immagine, title e subtitle
'Prezzo.Text ="8 euro"
If cell <> 0 Then
clvGrid.ReplaceAt(row, rowpnl, cellheight, row)
Else
clvGrid.Add(rowpnl, cellheight, row) 'add the Row Panel to the CLV
Log (cont)
Log (cell)
cont = cont +1
Log (cont)
End If
Next
End Sub
Sub ivIncr_Click
Dim iv As ImageView = Sender
Dim row As Int =clvGrid.GetItemFromView(iv)
Dim rowpnl As Panel = clvGrid.GetPanel(row)
Dim bckpnl As Panel = rowpnl.GetView(0) 'layout has a backpanel as its foundation
For i = 0 To bckpnl.NumberOfViews - 1
Dim cellpnl As Panel = bckpnl.GetView(i)
Dim bckp As Panel = cellpnl.GetView(0)
Dim iv1 As ImageView = bckp.GetView(5) 'increment icon
If iv1 = Sender Then
Dim lblqty As Label = bckp.GetView(4) 'label for quantity
Dim qty As Int = lblqty.Text
qty = qty + 1
lblqty.Text = qty
Exit
End If
Next
End Sub
Sub ivDecr_Click
Dim iv As ImageView = Sender
Dim row As Int =clvGrid.GetItemFromView(iv)
Dim rowpnl As Panel = clvGrid.GetPanel(row)
Dim bckpnl As Panel = rowpnl.GetView(0) 'layout has a backpanel as its foundation
For i = 0 To bckpnl.NumberOfViews - 1
Dim cellpnl As Panel = bckpnl.GetView(i)
Dim bckp As Panel = cellpnl.GetView(0)
Dim iv1 As ImageView = bckp.GetView(3) 'decrement icon
If iv1 = Sender Then
Dim lblqty As Label = bckp.GetView(4) 'label for quantity
Dim qty As Int = lblqty.Text
qty = qty - 1
If qty < 0 Then qty = 0
lblqty.Text = qty
Exit
End If
Next
End Sub