Hi im trying to remove multiple items with clv.RemoveAt(index) but works a bit odd, sometimes delete 2 items of 3, others 1 of 3.
Am i doing it right?
Am i doing it right?
B4X:
Sub Class_Globals
Private xui As XUI
Private vActivity As B4XView
Private vCodProducto As Int
Private lblNombreProducto, lblConIva, lblSinIVA As Label
Private txtCantidad As B4XView
Type ItemPedido (vCodProducto As Int,txtCantidad As B4XView,lblNombreProducto As Label, lblConIva As Label, lblSinIVA As Label)
Private clvProductos As CustomListView
Private vSelectedItems As List
Private vBaseColor, vSelectedColor As Int
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(activity As B4XView)
vActivity = activity
vActivity.RemoveAllViews
vActivity.LoadLayout("frmNuevoPedido")
vSelectedItems.Initialize
vBaseColor = 0xFFA8CDAA
vSelectedColor = 0xFF0686CC
CargarPedido
End Sub
Private Sub CargarPedido
For i = 1 To 50
Dim icp As ItemPedido
icp.Initialize
clvProductos.Add(CrearItemProducto(i,"Hola"&i,i*1000,i*1000*1.21,i,icp),icp)
Next
End Sub
Private Sub CrearItemProducto(codigo As Int,nombre As String,precio_sin_iva As String, precio_con_iva As String, cantidad As Int, icp As ItemPedido) As B4XView
Dim item As B4XView = xui.CreatePanel("")
item.SetLayoutAnimated(0,0,0,clvProductos.GetBase.Width,85dip)
item.LoadLayout("ItemPedido")
vCodProducto = codigo
lblNombreProducto.Text = nombre
lblConIva.Text = precio_con_iva
lblSinIVA.Text = precio_sin_iva
txtCantidad.Text = cantidad
txtCantidad.Color = xui.Color_Transparent
icp.lblConIva = lblConIva
icp.lblSinIVA = lblSinIVA
icp.lblNombreProducto = lblNombreProducto
icp.vCodProducto = vCodProducto
Return item
End Sub
Sub cmdMenu_Click
#if B4A
StartActivity(Menu)
#end if
End Sub
Sub cmdExit_Click
#If B4A
CallSubDelayed(Main,"CloseMe")
#End If
End Sub
Sub cmdEditClient_Click
'mesaje con input
End Sub
Sub cmdFinalizar_Click
End Sub
'Delete all selected items
Sub cmdEliminar_Click
For Each i In vSelectedItems
Log(i)
clvProductos.RemoveAt(i)
Next
vSelectedItems.Clear
End Sub
Sub cmdAnadir_Click
End Sub
'This function handle the painting and selection of items.
Sub clvProductos_ItemClick (Index As Int, Value As Object)
If vSelectedItems.IndexOf(Index) <> -1 Then
clvProductos.GetPanel(Index).Color = vBaseColor
vSelectedItems.RemoveAt(vSelectedItems.IndexOf(Index))
Else
vSelectedItems.Add(Index)
clvProductos.GetPanel(Index).Color = vSelectedColor
End If
End Sub