Spanish Devuelve vacios xcustomlistview

benji

Active Member
Licensed User
Longtime User
estoy usando la clase, mostrada aca https://www.b4x.com/android/forum/t...-cross-platform-customlistview.84501/#content

el tema es que se crea sin problemas la lista, pero cuando quiero obtener los datos de la lista, tengo los objetos en blanco.

B4X:
Sub Process_Globals
    Private Xui1 As XUI
    Type ItemValue (label1 As Label, label2 As Label, txt As EditText)
End Sub

Sub Globals
    Private CLV1 As CustomListView
    Private lblProducto As Label
    Private btnMas As Button
    Private txtcantidad As EditText
    Private btnMenos As Button
    
    
    Dim CurProd As Cursor
    Dim CurTicket As Cursor
    Dim CurVentas As Cursor
    
    Private lblPrecio As Label
    Private btnTotal As Button
    Private btnSalir As Button
    Private lblTotal As Label
    Private txtTotal As EditText
    
    Dim AuxTitulo As String
    Dim AuxBaja1 As String
    Dim AuxBaja2 As String
    Dim Folio As Int
    
    Dim StrOut As OutputStream
    Dim StrTitulo,StrAtencion,StrHora,StrFecha,StrValor,StrPie1,StrPie2 As String
    Dim ByTitulo(),ByAtencion(),ByHora(),ByValor(),ByPie1(),ByPie2() As Byte
    Dim strbyte(3) As Byte
    Dim strbyte2(1) As Byte
    Dim strbyte3(3) As Byte
    Dim strbyte4(2) As Byte
    Dim ByteBig(4) As Byte
    Dim BWByte(3) As Byte
    Dim Conv As ByteConverter
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim iv As ItemValue
    iv.Initialize
    iv.label1.Initialize("label1")
    iv.label2.Initialize("label2")
    iv.txt.Initialize("txt")

    Activity.LoadLayout("POSale")
    Activity.Title = "Punto Venta"
    CurProd = Main.DBMain.ExecQuery("Select * from Productos")
    If CurProd.RowCount > 0 Then
        For i = 0 To CurProd.RowCount - 1
            CurProd.Position = i
            iv.label1.Text = CurProd.GetString("Productos")
            iv.label2.Text = CurProd.GetInt("Precio")
            iv.txt.Text = "0"

            CLV1.Add(Create_Item(iv),iv)

        Next
    End If
        
End Sub

Private Sub Create_Item (iv As ItemValue) As B4XView
Dim p As B4XView = Xui1.CreatePanel("")
    
    p.SetLayoutAnimated(0,0,0,100%x,70dip)
    p.LoadLayout("Item")
    iv.label1 = lblProducto
    iv.label2 = lblPrecio
    iv.txt = txtcantidad
    Return p
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btnMas_Click
    Dim index As Int = CLV1.GetItemFromView(Sender)
    Dim iv As ItemValue = CLV1.GetValue(index)
    Dim i As Int
    Dim iTotal As Int
    Dim iPrecio As Int
    Dim iCant As Int
    Dim iLabelProd As String
    Dim iLabelPrecio As String

    iLabelProd = iv.label1.Text
    iLabelPrecio = iv.label2.Text
    iCant = iv.txt.Text
    
    iCant = 0
    iCant = iv.txt.Text
    iCant = iCant + 1
    iv.txt.Text = iCant
    If iv.txt.Text > 0 Then
        iv.txt.Color = Colors.Green
        iv.txt.TextColor = Colors.Black
    Else
        iv.txt.Color = Colors.Black
        iv.txt.TextColor = Colors.White
    End If
    
    iTotal = 0
    iCant = 0
    iTotal = txtTotal.Text
    iTotal = iTotal + iPrecio
    txtTotal.Text = iTotal
End Sub

el problema en especifico lo tengo en el btnMas_Click, en esa fila tengo dos botones, uno para sumar y uno restar, deberia retornar el valor de los dos labels y yo poder sumar y agregar la suma en edittext...
pero el getvalue viene en blanco
 

josejad

Expert
Licensed User
Longtime User
Hola:

Fíjate que el objeto iv se lo estás pasando como valor al CLV aquí

B4X:
 CLV1.Add(Create_Item(iv),iv)

pero al crear el ítem, sólo estás asignando los valores a las etiquetas, y esos valores no los estas recuperando al hacer el
CLV1.GetValue(index).

Prueba a poner logs para ver qué valores estás recuperando, por ejemplo:
B4X:
CLV1.GetValue(index)

A mí por ejemplo se me ocurre algo como asignarle tu objeto iv al tag del panel que estás creando en Create_Item
B4X:
Private Sub Create_Item (iv As ItemValue) As B4XView
    Dim p As B4XView = Xui1.CreatePanel("")
   
    p.SetLayoutAnimated(0,0,0,100%x,70dip)
    p.LoadLayout("Item")
    lblProducto = iv.label1
    lblPrecio = iv.label2
    txtcantidad = iv.txt
    p.Tag = iv 'AQUÍ ASIGNAMOS EL OBJETO AL TAG DEL PANEL PARA LUEGO RECUPERARLO
    Return p
End Sub

Así, en btnMas_Click podemos recuperarlo:
B4X:
Sub btnMas_Click
    Dim index As Int = CLV1.GetItemFromView(Sender)
    Log(index)
    Dim iv As ItemValue = CLV1.GetPanel(0).Tag
    'Log(CLV1.GetPanel(0).Tag)
    Log(iv.label2.Text)
.....
.....

Probablemente haya alguna forma más eficiente
 

benji

Active Member
Licensed User
Longtime User
Gracias, lo voy a probar. Por mientras como parche, asigne los valores a un array, usando el mismo indice.
 
Top