#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
'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 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 row = 0 To 5
'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
Dim cellpnl As Panel = bckpnl.getview(0) '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 = "Pizza Margherita 7 €"
Dim Stitle As Label = bckp.GetView(2) 'subtitle
Stitle.Text = "Sugo,Mozarella"
Dim Prezzo As Label = bckp.GetView(3) 'nuova label posta dopo immagine, title e subtitle
Prezzo.Text ="8 euro"
'Center cell panel
Dim cellpnl As Panel = bckpnl.getview(1) 'center cell
cellpnl.LoadLayout("lytCell")
Dim bckp As Panel = cellpnl.GetView(0)
Dim image As ImageView = bckp.GetView(0) 'image view
image.Bitmap = LoadBitmapSample(File.DirAssets,"pizw.png",bckp.Width, bckp.Height/2)
Dim title As Label = bckp.GetView(1) 'title
title.Text = "Pizza Wurstel 8 € "
Dim Stitle As Label = bckp.GetView(2) 'subtitle
Stitle.Text = "Pomodoro ,mozarella, Wurstel"
' Stitle.Ellipsize = "END"
'load Quantity, etc data too
'Right cell panel
Dim cellpnl As Panel = bckpnl.getview(2) 'right cell
cellpnl.LoadLayout("lytCell")
Dim bckp As Panel = cellpnl.GetView(0)
Dim image As ImageView = bckp.GetView(0) 'image view
image.Bitmap = LoadBitmapSample(File.DirAssets,"pizsal.png",bckp.Width, bckp.Height/2)
Dim title As Label = bckp.GetView(1) 'title
title.Text = "Pizza Sasisccia secca 5 €"
Dim Stitle As Label = bckp.GetView(2) 'subtitle
Stitle.Text = "Pomodoro ,mozarella, Sasiccia"
'load Subtitle, Quantity, etc data too
clvGrid.Add(rowpnl, cellheight, row) 'add the Row Panel to the CLV
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