Android Question xCustomListView... Flexible?

Hello there! I have a question, I want to touch a button with the cart and add the item to a different module where there is a list with the items in the cart. I make this code but when y touch on the button it creates a new item in the active list.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("General")
    
    ListaProductos.Initialize
    ListaProductos.Add(CreateMap("nombre":"Harina COLOLO 0000 X 1kg", "marca":"COLOLO",  "comercio":"El Vasco",  "precio":90.0, "unidad":1.0, "imagen": LoadBitmap(File.DirAssets , "harina cololo.jpg")))
    ListaProductos.Add(CreateMap("nombre":"Alfajor Clásico PORTEZUELO chocolate", "marca":"PORTEZUELO",  "comercio":"El Vasco",  "precio":15.0, "unidad":1.0, "imagen": LoadBitmap(File.DirAssets , "alfajor.jpg")))
    ListaProductos.Add(CreateMap("nombre":"Aceite OPTIMO de girasol X 1lt ", "marca":"OPTIMO",  "comercio":"El Vasco",  "precio":45.0, "unidad":1.0, "imagen": LoadBitmap(File.DirAssets , "aceite.jpg")))
    ListaProductos.Add(CreateMap("nombre":"Arroz blanco SAMAN X 1kg", "marca":"SAMAN",  "comercio":"El Vasco",  "precio":50.0, "unidad":1.0, "imagen": LoadBitmap(File.DirAssets , "arroz.jpg")))
    
    Dim xui As XUI
    For Each newArt As Map In ListaProductos
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0,0, clv.AsView.Width, 190dip)
        p.LoadLayout("Producto_Super1")  'layout has 5 labels
        nombre.Text = newArt.Get("nombre")
        marca.Text ="Marca: " & newArt.Get("marca")
        comercio.Text = "Comercio: " & newArt.Get("comercio")
        unidad.Text = newArt.Get("unidad")
        precio.Text = newArt.Get("precio")
        imagen.Bitmap = newArt.Get("imagen")
        clv.Add(p, newArt)
    Next

End Sub

Sub carrito_Click
    
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    
        p.SetLayoutAnimated(0, 0,0, clv.AsView.Width, 190dip)
        p.LoadLayout("Producto_Super1")
        nombre.Text = newArt.Get("nombre")
        marca.Text ="Marca: " & newArt.Get("marca")
        comercio.Text = "Comercio: " & newArt.Get("comercio")
        unidad.Text = newArt.Get("unidad")
        precio.Text = newArt.Get("precio")
        imagen.Bitmap = newArt.Get("imagen")
        clv.Add(p, newArt)
    
End Sub

WhatsApp Image 2021-01-11 at 23.31.48.jpeg

If I touch on the cart button in the last item it create a new item but in the active activity, not in the "Carrito" activity. Something like that:

WhatsApp Image 2021-01-11 at 23.31.58.jpeg
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @Bruno Ramos
  1. For starters you should use an SQLite database instead of lists, it will make your life a lot easier.
  2. You should activate just 1 list in the starter, then share that list throughout all your modules.
  3. But saying that (2), you should be using a database (1)
I'm going to presume that you are not using a database or a shared starter list. B4XPages would be great for this example...
 
Upvote 0
Top