Android Example CustomCardView Base On CustomListview Module

This is a module base on CustomListview, all function same with CustomListview I call it CustomCardView. Hope this help.

B4X:
For I = 0 To 5
'(the 47%x is cardview width, and the 45%y is the cardview height)
        Listview_CV.Add(CreateListItem(47%x, 45%y), 45%y, I)
        btn.Text = "Button" & I
Next

B4X:
Sub CreateListItem(Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
    Activity.AddView(p, 0, 0, Width, Height)
    p.LoadLayout("Custom_Button")
    p.RemoveView
    Return p
End Sub

upload_2018-3-31_12-21-15.png
 

Attachments

  • CustomCardViewExample.zip
    14.2 KB · Views: 643
  • CustomCardView.bas
    8.6 KB · Views: 612

Xfood

Expert
Licensed User
Hi, I was trying this nice class, but if after populating
I would like to clear the entire list and repopulate it?
I tried to insert a button that does a clear, and then repopulates, but the screen and the Listview_CV remains empty, why?

B4X:
Private Sub Popola_Click
    Listview_CV.Clear
    For I = 0 To 5
        '(the 47%x is cardview width, and the 45%y is the cardview height)
        Listview_CV.Add(CreateListItem(47%x, 45%y), 45%y, I)
        btn.Text = "Button" & I
    Next
End Sub
 

Xfood

Expert
Licensed User
hi, thanks to a member on the Italian forum @Sagenut to this post, he added this line in the original class in the sub clear, and now everything seems to work

B4X:
'Clears all items.
Public Sub Clear
    items.Clear
    panels.Clear
    sv.Panel.Height = 0
    LastPanelTop = 0   '<<<<<========== Ho aggiunto questa riga
    For i = sv.Panel.NumberOfViews - 1 To 0 Step -1
        sv.Panel.RemoveViewAt(i)
    Next
End Sub


 

Xfood

Expert
Licensed User
thanks to Sagenut of the Italian forum, who,
following my requests, he modified this magnificent class,
to be able to manage from 1 to 4 columns, for those interested, post 14

1719496910765.png
 
Last edited:
Top