iOS Question b4x customlistview

Uniko Sistemi srl

Active Member
Licensed User
Hello everybody I would like some advice to start a new project. I would like to create a very simple version of card collection, I would like to have my list that I compose every time I associate a new card. I would like the list to have only 2 columns. what should I do? with customlistview can I manage 2 items on the same line which are independent if I click them? thank you
 

Uniko Sistemi srl

Active Member
Licensed User
Don't use the CLV click event. Each item will be in a separate panel and you will handle the panel's click event.
so it is better to prepare the panels in the designer or from code every time I have a tile I create everything with the dimensions in such a way that they are aligned?
thank you
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
whe you create a CLV you should initialize the view like panel (or any view that is inside that panel) and give it an event name. then all you need is to use the SENDER object to get the correct item data. you can store the data you like in the Tag property of that view.

something like this:
NOTE: to run this code you need to create a Layout file named Layout1 that has a XUI Customlistview in it (B4J, Xui-Views)


B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private CustomListView1 As CustomListView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    For i = 0 To 100
        CustomListView1.Add(createItem($"item ${i}"$,CustomListView1.AsView.Width,CustomListView1.AsView.Height/18),$"item ${i}"$)
    Next
End Sub


Private Sub createItem (value As String, width As Float, height As Float) As B4XView
    Dim p As B4XView = xui.CreatePanel("pnl")
    p.Width = width
    p.Height = height
    p.Color = xui.Color_Green
    p.Tag = value
  
    Dim lbl As B4XView = createLabel("lbl")
    lbl.Text = "I am a clickable Label"
    lbl.TextColor = xui.Color_Black
    lbl.TextSize = 14
    lbl.SetTextAlignment("CENTER", "LEFT")
    lbl.Tag = "Label: " & value
  
    Dim btn As B4XView = createButton("btn")
    btn.Text = "Click me"
    btn.TextColor = xui.Color_Red
    btn.TextSize = 14
    btn.SetTextAlignment("CENTER", "CENTER")
    btn.Tag = "Button: " & value
  
    p.AddView(lbl,0,0,width*0.65,height)
    p.AddView(btn,width*0.65,0,width*0.35,height)
    Return p
End Sub

Private Sub btn_Click
    Dim btn As B4XView = Sender
    Log(btn.Tag.As(String))
End Sub

Private Sub lbl_MouseClicked (EventData As MouseEvent)
    Dim lbl As B4XView = Sender
    Log(lbl.Tag.As(String)) 
    EventData.Consume
End Sub
 
Private Sub createLabel(eventName As String) As B4XView
    Dim lbl As Label
    lbl.Initialize(eventName)
    Return lbl
End Sub

Private Sub createButton(eventName As String) As B4XView
    Dim btn As Button
    btn.Initialize(eventName)
    Return btn
End Sub

EDIT: this example creates the views in runtime, Erel's was talking above about a solution to load the views from a layout file. both work of course it is up to you how to load your views.
 
Upvote 0
Top