Android Question CustomListVIew

luisro

Member
Licensed User
I have this code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    actividad
End Sub

Sub actividad

    For i = 1 To 20
        Dim p As Panel
        Bitmap1.Initialize(File.DirAssets,"Icon.png")
        Bitmap2.Initialize(File.DirAssets,"fverde.png")
        Bitmap3.Initialize(File.DirAssets,"froja.png")
        Bitmap4.Initialize(File.DirAssets,"iconoleche.png")
        Bitmap5.Initialize(File.DirAssets,"iconoazucar2.png")
        Bitmap6.Initialize(File.DirAssets,"iconoin.png")
        p.Initialize("")
        p.Color = Colors.White
   
        'IMAGEN DEL PRODUCTO    //////////////////////////////////////
        imagen.Initialize("")
        p.AddView(imagen,5dip,5dip,65dip,65dip)
        imagen.Bitmap=Bitmap1
   
        'FLECHAS//////////////////////////////////////////////////////
       
        'VERDE
        imagen2.Initialize("")
        p.AddView(imagen2, 180dip, 55dip, 240dip,50)
        imagen2.Bitmap=Bitmap2
       
        'ROJA
        imagen3.Initialize("")
        p.AddView(imagen3, 180dip, 70dip, 240dip,50)
        imagen3.Bitmap=Bitmap3
       
        'iCONOS LEYENDA////////////////////////////////////////////////
        imagen4.Initialize("")
        p.AddView(imagen4,80dip, 35dip, 240dip, 60)
        imagen4.Gravity =  Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        imagen4.Bitmap=Bitmap4
       
        imagen5.Initialize("")
        p.AddView(imagen5, 100dip, 35dip, 240dip, 60)
        imagen5.Gravity =  Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        imagen5.Bitmap=Bitmap5
       
       
        imagen6.Initialize("")
        p.AddView(imagen6,120dip, 35dip, 240dip, 60)
        imagen6.Gravity =  Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        imagen6.Bitmap=Bitmap6
       
        'LOTE/////////////////////////////////////////////////////////
        Dim lbl6 As Label
        lbl6.Initialize("")
        p.AddView(lbl6, 25dip,45dip,65dip,65dip)
        lbl6.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        lbl6.Tag="Label3"
        lbl6.Text = "07/17"
        lbl6.TextSize = 11
        lbl6.TextColor = Colors.Black
       
        'TITULO/////////////////////////////////////////////////////////
        Dim lbl2 As Label
        lbl2.Initialize("")
        p.AddView(lbl2, 80dip, 5dip, 240dip, 30)
        lbl2.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        lbl2.Tag="Label2"
        lbl2.Text = "Chicha Kiana"
        lbl2.TextSize = 14
        lbl2.TextColor = Colors.Black
   
        'GRAMAJE/////////////////////////////////////////////////////////
        Dim lbl3 As Label
        lbl3.Initialize("")
        p.AddView(lbl3, 80dip, 25dip, 240dip, 30)
        lbl3.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        lbl3.Tag="Label3"
        lbl3.Text = "500"&"Gr"
        lbl3.TextSize = 13
        lbl3.TextColor = 0xFF424242
       
        If (i Mod 2)=0 Then
        'PRECIO//////////////////////////////////////////////////////////
        Dim lbl4 As Label
        lbl4.Initialize("")
        p.AddView(lbl4, 80dip, 65dip, 240dip,30)
        lbl4.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        lbl4.Tag="Label4"
        lbl4.Text = "10.000"&"BS"
        lbl4.TextSize = 13
        lbl4.Typeface = Typeface.DEFAULT_BOLD
        lbl4.TextColor = Colors.Black
        Else
            Dim lbl4 As Label
            lbl4.Initialize("")
            p.AddView(lbl4, 80dip, 65dip, 240dip,30)
            lbl4.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
            lbl4.Tag="Label4"
            lbl4.Text = "5.000"&"BS"
            lbl4.TextSize = 13
            lbl4.Typeface = Typeface.DEFAULT_BOLD
            lbl4.TextColor = Colors.Black
        End If
        'DIFERENCIA DE PRECIO////////////////////////////////////////////
        Dim lbl5 As Label
        lbl5.Initialize("")
        p.AddView(lbl5, 255dip, 66dip, 240dip,30)
        lbl5.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        lbl5.Tag="Label4"
        lbl5.Text = "1500"
        lbl5.TextSize = 13
        lbl5.TextColor = Colors.Black   
       
        clv1.Add(p,150,i)
        Next
   
End Sub

There is some way to click on the list (CustomListView) the panel (p) in the position (Value) can copy everything it contains and assign everything to the panel (panel1)

ejemplo.png

The images and tags and their contents (everything) from panel (i) from customlistview to Panel2. Thanks.
 

luisro

Member
Licensed User
Ok, load the panel from the design with the "p.LoadLayout (" ")" delete the images so test.

1.load panel (p) with views made in the designer.
2.load the values for the views.
3. Load the CLV with the panel (p) with a cycle for.
Now, I need to make Clv1_itemClick the panel (p) in position (i) the panel with all its views and their values. Exactly the same. Go to a panel (Panel2).

To have panel2 on top and CLV down it.

My intention with this app is to create a list of products with their characteristics and prices, and when you click on one, this is set in top. And take their price and compare them with all the products on the list, and each product marks its difference if it is above or below its value and shows an up or down arrow. And that the user sees fixed the product that he chose (i) and raise or lower the list.

B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
    panel2 = clv1.GetPanel(Index)
End Sub

This does not work for me or the truth I can not find the way.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think we understand what you're trying to achieve - this should work.

I would put a log or toast message in the click event and see if it is fired.

I'd even try creating it again - by using the autocomplete.. Sub <space> <tab> and then complete it.. then enter the owning view of the event against it.

It should work, but something isn't (obviously).. Now the 'fun' starts in debugging and working out if the event has fired or if it hasn't and if it has then why the information isn't being displayed.

It looks like your Event is missing a whole lot of detail to be honest. i.e. Panel2 should contain some labels and then you should update those and display them on the Panel.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
try this ...
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)   
    Dim pnl As Panel = clv1.GetPanel(Index)   
    pnl.RemoveView  ' removes pnl from CLV parent panel
    Panel2.AddView(pnl, 0 , 0, Panel2.Width, Panel2.Height)
End Sub
 
Upvote 0

luisro

Member
Licensed User
Thanks for your answers, I ran your code, I had to load the (clv1) again in each clv1_ItemClick, since I have to modify all the prices of the products in relation to the clicked, and, because each click deletes the item from the list (Clv1).

B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
    panel2.RemoveAllViews
    Dim pnl As Panel = clv1.GetPanel(Index)
    pnl.RemoveView  ' removes pnl from CLV parent panel
    panel2.AddView(pnl, 0 , 0, panel2.Width, panel2.Height)
    clv1.Clear
    For i = 1 To 20
        p.Initialize("")
        Activity.AddView(p,0,0,100dip,100dip)
        p.LoadLayout("2")
        p.RemoveView
        label1.textColor = Colors.Black
        label2.textColor = Colors.Black
        label3.textColor = Colors.Black
        If (i Mod 2)=0 Then
            label1.Text = 100000
            label2.Text = 100000
            label3.Text = 100000
        Else
            label1.Text = 200000
            label2.Text = 200000
            label3.Text = 200000
        End If
        clv1.Add(p,150,i)
    Next
End Sub


All the data will come from a DB, could have an event for when Click on the imagenview image enlarges ?. Clv1_Itemclick (background) load Panel2, Imageview (i) enlarge the image.

I do not like to bother, but this class just barely understands it.

Post: I saw the example of the button and ChekBox, with that I get the click event in the imageview how to expand it?
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
could have an event for when Click on the imagenview image enlarges ?. Clv1_Itemclick (background) load Panel2, Imageview (i) enlarge the image.

A little unsure of your question ...
When you click on Clv1 Item/Panel , the item is removed from list and copied to panel2 .. the image view(panel2) automatically enlarges ?

B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
  Dim pnl As Panel = clv1.GetPanel(Index)
  pnl.RemoveView ' removes pnl from CLV parent panel
  Panel2.AddView(pnl, 0 , 0, Panel2.Width, Panel2.Height)
  Dim img As ImageView = pnl.GetView(0) '1st Item on panel
  img.SetLayoutAnimated(500, img.Left, img.Top, 150dip, 150dip)
End Sub

If you click on Clv1 Image that Image enlarges ...?
(you would want to create global var to store Item Index so previously clicked item images are resized to back to normal.)

B4X:
imagen.Initialize("Imagen")

Sub Imagen_Click
  Dim index As Int = clv1.GetItemFromView(Sender)
  Dim pnl As Panel = clv1.GetPanel(index)
  Dim img As ImageView = pnl.GetView(0) '1st Item on panel
  img.SetLayoutAnimated(500, img.Left, img.Top, 150dip, 150dip)
End Sub

If you are unsure of the Imageview position within panel you can loop thru the views and test for view type ..
If you have multiple Imageviews on the Clv Item .. assign each an Identify Tag..

B4X:
For Each v As View In pnl.GetAllViewsRecursive
  If v Is ImageView Then
    If v.Tag = "This is correct image" Then
      Dim img As ImageView = v
      img.SetLayoutAnimated(500, img.Left, img.Top, 150dip, 150dip)
    End If
  End If
Next

Please start a new thread for any further questions / issues.
 
Last edited:
Upvote 0
Top