Android Question Add sections in listview

Avansys

Member
Licensed User
Longtime User
How I can add sections in a listview?

Something like the attached image.

What I want is that when you slide down, the title stay in top, in each section.

Is there a library or something?

Thanks.
 

Attachments

  • andy-300x244.png
    andy-300x244.png
    35.1 KB · Views: 197

mangojack

Expert
Licensed User
Longtime User
try this ...
B4X:
Dim  list1 As List
Dim  Item , newChar, oldChar As  String
  
   'whatever your data source .. sort it alphabetically first
   list1.Initialize
   list1.Add("Apples")
   list1.Add("Bananas")
   list1.Add("Beans")
   list1.Add("Figs")
   list1.Add("Fish")
   list1.Add("Fruit")
   list1.Add("Grapes")
   list1.Add("Melons")
   list1.Add("Mullberrys")
  
   'format your listview
   ListView1.SingleLineLayout.ItemHeight = 24dip
   ListView1.SingleLineLayout.Label.TextSize = 14
   ListView1.SingleLineLayout.Label.Color = Colors.DarkGray
   ListView1.SingleLineLayout.Label.TextColor= Colors.LightGray

   ListView1.TwoLinesLayout.Label.Left = 20dip  
   ListView1.TwoLinesLayout.ItemHeight=40dip
   ListView1.TwoLinesLayout.Label.TextSize = 18
   ListView1.TwoLinesLayout.Label.TextColor= Colors.White  
  
   'add listview data
   For  i = 0 To list1.Size -1
    
     'test for new Alpha  .. if so show new alpha prior to item list  eg: C  Cake
     Item = list1.Get(i)
     newChar = Item.SubString2(0,1)
     If newChar <> oldChar Then  
       ListView1.AddSingleLine(newChar)
       oldChar = newChar    
     End If
        
     ListView1.Addtwolines(Item,"")  
    
   Next
 
Last edited:
Upvote 0

Avansys

Member
Licensed User
Longtime User
Yeah, I already knew how to do it, I'm trying to make is when I slide down in the listview, headers not disappear.
 
Upvote 0
Top