Android Question CustomListView / Xui Views Library

Antonio Ferreira

Member
Licensed User
Longtime User
When I add XUI Views Library to my project, all my CustomListViews stop working (Too many parameters on CreatlistItem).
I use CustomListView.bas version 1.10
There is any workaround solution for this problem. I have to many customListviews on my project.
I want to develop new listviews with Xcustomlistview and updating the old listviews over time.
B4A Version 9.5
 

Mahares

Expert
Licensed User
Longtime User
my CustomListViews stop working (Too many parameters on CreatlistItem)
I am pretty sure this is what you need to do:
1. Remove the class module and use the latest version of the library If you upgrade to B4A version 9.80 (free upgrade) xCusstomlistview (1.72) is an internal library and included when you upgrade to version 9.80 (free)
2. You need to open all the layouts that have the customlistview and then save them after you check Xcustomlistview lib. This way the new features will take effect. That should take care of you.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hi:

You should not use the customlistview class (the bas file). Customlistview is now a internal library. Delete the bas file and select xcustomlistview from the libraries.

Update to 9.8
 
Upvote 0

Antonio Ferreira

Member
Licensed User
Longtime User
I am pretty sure this is what you need to do:
1. Remove the class module and use the latest version of the library If you upgrade to B4A version 9.80 (free upgrade) xCusstomlistview (1.72) is an internal library and included when you upgrade to version 9.80 (free)
2. You need to open all the layouts that have the customlistview and then save them after you check Xcustomlistview lib. This way the new features will take effect. That should take care of you.
Thank you Mahares, but i don´t have the layouts for the views (button, labels) in the designer . I only have the layout for the Customlistview.
I add the labels,button to the customlistview (Item_LayoutCreator) with LayoutPanel.AddView(lbl3, 5dip, 45dip, 100%x, 20dip).
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I only have the layout for the Customlistview.
That is ok. Just open the customlistview layout and save it again with the new lib in effect. Also, as Sagenut suggested, you do not need to check the xCustomlistView if you have checked the XUI Views library, but even if you check it along with the XUI Views, there is no harm and it does not double up or cause problems.
 
Upvote 0

Antonio Ferreira

Member
Licensed User
Longtime User
That is ok. Just open the customlistview layout and save it again with the new lib in effect. Also, as Sagenut suggested, you do not need to check the xCustomlistView if you have checked the XUI Views library, but even if you check it along with the XUI Views, there is no harm and it does not double up or cause problems.
Thank you Mahares for your help.
I upgrade B4A to 9.8
I remove Customlistview.bas
I remove the old custoslistview from the layout e add the new customlistview to the layout file.
When I run, I don´t have any error, but listview is blank and don´t respond to any event.
This is my activity code.

B4X:
Sub Globals
    Private Btn_sair As Button
    Dim Bmp1 As Bitmap
    Private Label1 As Label
    Private clv As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Menu_OT")
    Activity.Title="  " & "MENU  -  Ordens de Trabalho"
    Bmp1.Initialize(File.DirAssets, "obras_32.png")
    Btn_sair.Text="Exit"
    Label1.Text="Selecionar_a_opção :"
      
    clv.Clear
    ' clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width, 52dip),52dip,1)
    ' this is my old code, where clv.add() had 3 parameters. The parameter height disapear on the new customlistview.Add   
    
    clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width,52dip), 1)
    clv.Add(CreateListItem("Informação de O.T.",clv.AsView.Width,52dip),4)
    clv.Add(CreateListItem("Abertura de O.T.",clv.AsView.Width, 52dip), 2)
    clv.Add(CreateListItem("Historico do ativo",clv.AsView.Width, 52dip),3)

End Sub

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    
    Dim img As ImageView
    img.Initialize("")
    img.Bitmap=Bmp1
        
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextColor = Colors.White
    
    lbl.TextSize = 16
    p.AddView(img, 10dip, 10dip, 32dip, 32dip) 'view #0
    p.AddView(lbl,55dip,5dip, Width, 36dip)    'view #1

    Return p
End Sub


Sub clv_ItemClick (Position As Int, Value As Object)
    Select Value
        Case 1
            Activity.Finish
            StartActivity(FILTRO_OT2)
        Case 2
            CallSubDelayed3(OTN, "ShowList","Menup2",0)
        Case 3
            StartActivity(Equip_Hist2)
        Case 4
            StartActivity(OT_INFO2)
    End Select
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
When I run, I don´t have any error, but listview is blank



I cannot see where you are setting the panels position. width. height etc.
B4X:
p.SetLayoutAnimated(0, 0, 0, Width, Height)


I think it would be better to add you views {Label, Imageview} to another layout ,and just load that to the panel.

B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("clvItems")
    img.Bitmap=Bmp1
    Label1.Text = Text
    Return p
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
but listview is blank and don´t respond to any event.
Your code should look like this:
B4X:
Sub Globals
    Private Btn_sair As Button
    Dim Bmp1 As Bitmap
    Private Label1 As Label
    Private clv As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Menu_OT")
    Activity.Title="  " & "MENU  -  Ordens de Trabalho"
    Bmp1.Initialize(File.DirAssets, "obras_32.png")
    Btn_sair.Text="Exit"
    Label1.Text="Selecionar_a_opção :"
      
    clv.Clear    
    clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width),52dip, 1)
    clv.Add(CreateListItem("Informação de O.T.",clv.AsView.Width),52dip,4)
    clv.Add(CreateListItem("Abertura de O.T.",clv.AsView.Width), 52dip, 2)
    clv.Add(CreateListItem("Historico do ativo",clv.AsView.Width), 52dip,3)
End Sub

Sub CreateListItem(Text As String, Width As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    
    Dim img As ImageView
    img.Initialize("")
    img.Bitmap=Bmp1
        
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextColor = Colors.White
    
    lbl.TextSize = 16
    p.AddView(img, 10dip, 10dip, 32dip, 32dip) 'view #0
    p.AddView(lbl,55dip,5dip, Width, 36dip)    'view #1

    Return p
End Sub


Sub clv_ItemClick (Position As Int, Value As Object)
    Select Value
        Case 1
'            Activity.Finish
'            StartActivity(FILTRO_OT2)  'for testing I commented this
            Log(Value)
        Case 2
'            CallSubDelayed3(OTN, "ShowList","Menup2",0)
            Log(Value)
        Case 3
'            StartActivity(Equip_Hist2)
            Log(Value)
        Case 4
'            StartActivity(OT_INFO2)
            Log(Value)
    End Select
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
@Mahares I'm slightly confused .. It was suggested to @Antonio Ferreira above to change to the newer internal xCLV lib .. and it would appear he has done so.

B4X:
clv.Clear ' clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width, 52dip),52dip,1) ' this is my old code, where clv.add() had 3 parameters. The parameter height disapear on the new customlistview.Add
clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width,52dip) , 1) , 4)
'.........................

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel


But your solution above is more tuned to the old CLV class ? (clv.Add(p, Width) , Height, Value)
B4X:
clv.Clear 
clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width),52dip, 1)



But apart from that ... adjusting your code I still get a blank output as stated above . only when adding the panel layout position do I see the views. (see Post #6)
B4X:
Sub CreateListItem(Text As String, Width As Int, Height) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    p.SetLayoutAnimated(0, 0, 0, Width, Height) '***********
    '................
 
Last edited:
Upvote 0

Antonio Ferreira

Member
Licensed User
Longtime User
Your code should look like this:
B4X:
Sub Globals
    Private Btn_sair As Button
    Dim Bmp1 As Bitmap
    Private Label1 As Label
    Private clv As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Menu_OT")
    Activity.Title="  " & "MENU  -  Ordens de Trabalho"
    Bmp1.Initialize(File.DirAssets, "obras_32.png")
    Btn_sair.Text="Exit"
    Label1.Text="Selecionar_a_opção :"
     
    clv.Clear   
    clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width),52dip, 1)
    clv.Add(CreateListItem("Informação de O.T.",clv.AsView.Width),52dip,4)
    clv.Add(CreateListItem("Abertura de O.T.",clv.AsView.Width), 52dip, 2)
    clv.Add(CreateListItem("Historico do ativo",clv.AsView.Width), 52dip,3)
End Sub

Sub CreateListItem(Text As String, Width As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
   
    Dim img As ImageView
    img.Initialize("")
    img.Bitmap=Bmp1
       
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    lbl.Text = Text
    lbl.TextColor = Colors.White
   
    lbl.TextSize = 16
    p.AddView(img, 10dip, 10dip, 32dip, 32dip) 'view #0
    p.AddView(lbl,55dip,5dip, Width, 36dip)    'view #1

    Return p
End Sub


Sub clv_ItemClick (Position As Int, Value As Object)
    Select Value
        Case 1
'            Activity.Finish
'            StartActivity(FILTRO_OT2)  'for testing I commented this
            Log(Value)
        Case 2
'            CallSubDelayed3(OTN, "ShowList","Menup2",0)
            Log(Value)
        Case 3
'            StartActivity(Equip_Hist2)
            Log(Value)
        Case 4
'            StartActivity(OT_INFO2)
            Log(Value)
    End Select
End Sub

Thank you for your help. All is ok . Now is easy to update my project.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
:confused: whatever ... maybe its the fact I've been running on one eye for the past fortnight .. and not seeing strate . :)
 
Upvote 0

Antonio Ferreira

Member
Licensed User
Longtime User
@Mahares I'm slightly confused .. It was suggested to @Antonio Ferreira above to change to the newer internal xCLV lib .. and it would appear he has done so.

B4X:
clv.Clear ' clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width, 52dip),52dip,1) ' this is my old code, where clv.add() had 3 parameters. The parameter height disapear on the new customlistview.Add
clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width,52dip) , 1) , 4)
'.........................

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel


But your solution above is more tuned to the old CLV class ? (clv.Add(p, Width) , Height, Value)
B4X:
clv.Clear
clv.Add(CreateListItem("Consulta de O.T.",clv.AsView.Width),52dip, 1)



But apart from that ... adjusting your code I still get a blank output as stated above . only when adding the panel layout position do I see the views. (see Post #6)
B4X:
Sub CreateListItem(Text As String, Width As Int, Height) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    p.SetLayoutAnimated(0, 0, 0, Width, Height) '***********
    '................

Thank you . Mahares give me a solution for an easy update for my old listviews for the customlistviews . After do that, I can update these customlistviews to the xcustomlistviews over time, as you suggest. The problem is when i add to my project the library XUI Views (for updating to Xcustomlistviews) all my old listviewes don´t
work. After converting to the old ones to the more recent Customlistviewes (an easy update) i don´t have this problem.
 
Upvote 0
Top