I leave this code that may be interesting for whoever accesses this message.
In my case, I usually create a special panel that I add to the CustomListView.
The panel has inside, buttons, label, check, etc.
The registry key associated with the panel, I load it within the TAG of the panel.
Therefore, the need is that when clicking on a button, check, etc., to know the panel that contains them, and to extract from it its tag, which is the key.
With that explained, this is the code I usually use:
in this sample a use a Type of date.
(my special layout, have a panel, and 3 button insede (cmdAparca is one), labels, etc))
Type TD_VehiculosAsignables(Matricula As String, Empleado As Int , NombreEmpleado As String, EnTaller As Boolean , Disponible As Boolean, TXTParaCLV As CSBuilder, TxtParaclickEnClV As CSBuilder, AsignacionEnCurso As Boolean, IDUso As Int, Situacion As String, Color As Int )
first;: load CustomListView CLV
private Sub Cargar
Try
'get data from sql server.
Dim Sql As String
Sql = "SP_VehiculosAsignables_Select ?"
Dim Jdt As JdbcResultSet
'BETTER USE ASYNC methods an use wait for
Jdt = modGeneral.clsConnec.GetRecordSet2(Sql, Array As String(B4XMatriculaBusqueda.Text),True)
CLV.Clear
Do While Jdt.NextRow
'very important to DO DIM into DO WHILE
Dim TdV As TD_VehiculosAsignables
TdV.Matricula = modGeneral.clsConnec.GetTxt(Jdt,"Matricula")
TdV.Disponible = modGeneral.clsConnec.GetBoolean (Jdt,"Disponible")
TdV.Empleado= modGeneral.clsConnec.GetInt(Jdt,"Cod_Empleado")
TdV.EnTaller= modGeneral.clsConnec.GetBoolean (Jdt,"EnTaller")
TdV.NombreEmpleado = modGeneral.clsConnec.GetTxt(Jdt,"NombreEmp")
TdV.AsignacionEnCurso = modGeneral.clsConnec.GetBoolean (Jdt,"AsignacionEnCurso")
TdV.IDUso = modGeneral.clsConnec.GetInt(Jdt,"IDUso")
TdV.TXTParaCLV = modGeneral.clsConnec.GetTxtCSB(Jdt,"TXTParaCLV")
TdV.TxtParaclickEnClV= modGeneral.clsConnec.GetTxtCSB(Jdt,"TxtParaclickEnClV")
TdV.Situacion = modGeneral.clsConnec.GetTxtCSB(Jdt,"Situacion")
TdV.Color = modGeneral.clsConnec.GetInt (Jdt,"Color")
'Create custom layout an insert in clv:
CargarVehiculos(TdV)
'if you no use panel layout, you can add a text o better a CSBuilder WITH COLORS, fonts, etc..
'CLV.AddTextItem (TdV.TXTParaCLV,TdV)
Loop
If CLV.Size = 0 Then
CLV.AddTextItem("< Sin Datos>",Null)
End If
Catch
Log(LastException)
End Try
End Sub
click in button:
Private Sub cmdAparcar_Click
ClickEnBoton (Sender)
End Sub
private Sub ClickEnBoton(Boton As Button)
Try
PanelDetalle = GetPanelDelBoton(Boton)
Dim Clave As TD_VehiculosAsignables
Clave = PanelDetalle.Tag
If Clave <> Null Then
'DO something with key - Clave or value in key
'SetSituacion (Clave.Matricula,Boton.Tag )
End If
Catch
Log(LastException)
MsgboxAsync(LastException.Message,"Click situacion")
End Try
End Sub
Get Panel Container of button (or other controls ->CHANGE param as button)
private Sub GetPanelDelBoton(Boton As Button) As Panel
Try
Dim index As Int= CLV.GetItemFromView(Boton)
Dim pnl As Panel = CLV.GetPanel(index)
'sacar el control dentro del panel
' Return pnl
Dim PanelContenedor As Panel = pnl.GetView(0)
Return PanelContenedor'*************************************************
'*************************************************************************
'FOR get all controls and get, with name
For Each c As B4XView In pnl.GetAllViewsRecursive
Log(c)
If GetType(c).EndsWith ( "CheckBox") Then
Return c
End If
Next
Catch
Log(LastException)
End Try
Return Null
End Sub
¡¡ah... create and insert panel:
Sub CargarVehiculos(TDV As TD_VehiculosAsignables)
'this is importante for set the correct size in clv. double setlayoutanimated are required.
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, Activity.Width, 130dip)
p.LoadLayout("LayoutDetalleVehiculo")
p.SetLayoutAnimated(0, 0, 0, CLV.AsView.Width, PanelDetalle.Height)
'set test in controls of panel
' lwB4XMatricula.Text = TDV.Matricula
'set the key in panel.tag (for get in other code)
PanelDetalle.Tag = TDV
' lwlblTexto.Text = TDV.Situacion
' lwlblColor.Color = TDV.Color
CLV.Add( p,TDV)
End Sub
'something to do in button click:
private Sub SetSituacion(Matricula As String , Situacion As String)
Dim Sql As String
Sql = "SP_Vehiculos_Situacion_Update @Matricula=?, @Situacion=?, @Empleado=?"
modGeneral.clsConnec.ExecuteAndDecodeRespuesta(Sql,Array As String(Matricula,Situacion, modGeneral.V_Usuario.Codigo ),True ,False )
'load clv again:
' Cargar
MsgboxAsync(Matricula & " -> " & Situacion,"Clave")
End Sub