B4J Question sort buttons with preoptimizedclv

fhersof

Member
Please, a little help, I am tired of searching and not finding what I need; in attached project i get what is seen in image1 and i want what is seen in image2.
I appreciate any help.
imagen_1.png
imagen_2.png
 

Attachments

  • miniprojectbt.zip
    3.9 KB · Views: 179

Erel

B4X founder
Staff member
Licensed User
Longtime User
No reason to use PreoptimizedCLV for such short list.

Anyway:
B4X:
Sub InitView
    PCLV.Initialize(Me, "PCLV", CustomListView1)
    For i = 0 To 60 Step 3
        PCLV.AddItem(40dip,xui.Color_LightGray,Array(i, i + 1, i + 2))
    Next
    PCLV.ShowScrollBar = False 'no fast scrolling
    PCLV.ExtraItems = 5
    PCLV.Commit
End Sub

Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = CustomListView1.GetRawListItem(i)        
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        Dim data() As Object = item.Value
        pnl.LoadLayout("item")
        Button1.Text = data(0)
        Button2.Text = data(1)
        Button3.Text = data(2)
    Next
End Sub
 
Upvote 0

fhersof

Member
No reason to use PreoptimizedCLV for such short list.

Anyway:
B4X:
Sub InitView
    PCLV.Initialize(Me, "PCLV", CustomListView1)
    For i = 0 To 60 Step 3
        PCLV.AddItem(40dip,xui.Color_LightGray,Array(i, i + 1, i + 2))
    Next
    PCLV.ShowScrollBar = False 'no fast scrolling
    PCLV.ExtraItems = 5
    PCLV.Commit
End Sub

Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = CustomListView1.GetRawListItem(i)       
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        Dim data() As Object = item.Value
        pnl.LoadLayout("item")
        Button1.Text = data(0)
        Button2.Text = data(1)
        Button3.Text = data(2)
    Next
End Sub

It works perfectly, thank you very much
 
Upvote 0

fhersof

Member
Sorry, it was complicated for me to execute the following: I have 2 lists list.codes and list.names I want to show the list of names in the buttons and the list of codes in the tag of the buttons.
Please a little light
 
Upvote 0
Top