Voy cargando articulos en un ListView a medida que el usuario presiona un botón pero necesito comprobar en el LISTVIEW si ese articulo ya no existe para no volverlo a agregar y SI INCREMENTARLE uno en la 2° Línea.
ME AYUDAN?
B4X:
CargaArticulo (1,lbC.Text)
Sub CargaArticulo(cantidad As String ,articulo As String)
Dim eXISTE As Boolean
If eXISTE Then
'SI EXISTE EN EL LISTV AGREGARLE UNO A LA CANTIDAD
l1.AddTwoLines2 (cantidad + 1 , articulo, cantidad + 1)
Else
'SI NO EXISTE AGREGARLO
l1.AddTwoLines2(cantidad, articulo, cantidad)
End If
End Sub
Si quieres modificar ese item, primero lo buscas, cuando sepas el indice lo borras, y creas uno nuevo con los valores cambiados.
Seria algo asi:
B4X:
dim id as int
id= ComprobarExisteItem (articulo)
' si es diferente a -1 es que encontró el articulo
if id <> -1 then
' aqui añades el articulo cambiado o creas el codigo que te interese
..............
.............
l1.RemoveAt (id) ' borramos el item encontrado
end if
sub ComprobarExisteItem (articuloIn as string) as int
dim retorno as int
dim articulo, Itemlista as string
articulo= articuloIn
retorno = -1 ' devuelve esto si no encuentra item
For n=0 to l1.size-1 ' recuerda que el item 0 existe
itemlista = l1.GetItem(n)
if itemlista.ToLowerCase = articulo.ToLowerCase then
' si quieres que compruebe nombres en mayusculas o minusculas puedes poner la linea de abajo y quitar los string
' if l1.GetItem(n) = articuloIn then
retorno = n
exit ' sale del bucle for next para ir mas rápido
End If
Next
return retorno
end sub