Android Question Xcustomlistview sort items

nobbi59

Active Member
Licensed User
Longtime User
Put all numbers in a list before you add them. Then you can sort them. After that put them in the ListView.
 
Upvote 0

Addo

Well-Known Member
Licensed User
xclv will not have only numbers

example view will be

Name1 - number 100
Name2 - number 99
Name3 - Number 98
and so on

the sort that i am trying to archive

Name3 - Number 98
Name2 - Number 99
Name1 - Number 100

i dont get the point on how to use a list with XCLV in this case of sorting
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Where is the information coming from that you are putting in the items of the XCLV? How are you currently inserting the items? See (https://www.b4x.com/android/help/collections.html#list_sorttype) for a clue on how to assign each of your XCLV items to a Type, add that Type to a list and then sort the list by the Type. After your list is sorted, you can add your XCLV items in the sorted order to the XCLV.
 
Upvote 0

Addo

Well-Known Member
Licensed User
thats how i create the items

B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
   Dim p As Panel
   p.Initialize("")
   p.SetLayout(0, 0, Width, Height)
   p.LoadLayout("cellitem")
   label1.Text = " Name "
   labelnumber.Text = "100 "
   Return p
End Sub

what i am trying to do is sort based on labelnumber.text value i will look at the link now
 
Upvote 0

Addo

Well-Known Member
Licensed User
ok i am working now with the list but is this sorttype do have compare function ? because some times numbers will be equal and some times smaller than and bigger than other list numbers do sorttype will handle them normally in order ?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
It does ascending/descending. Check out the second parameter.
 
Upvote 0

Addo

Well-Known Member
Licensed User
here is a brief of what i am doing i dont know if its fine way it works any way but maybe will consume too much memory

B4X:
Sub creatuserpersonlist(Text As String) 
Dim parammsgnum() As String = Regex.Split("\~", Text)
Dim usr As Person
usr.name = parammsgnum(0)
usr.num = parammsgnum(1)
Persons.Add(usr)
Persons.SortType("num", True)

xclv.Clear

For i = 0 To Persons.Size - 1
Dim usr As Person
usr = Persons.Get(i)

xclv.Add(Createuserafterclearlist(usr.name, xclv.AsView.Width, 38dip), usr.name)
Sleep(0)
Next
  
End Sub

so each time person added xclv should cleared and re added for the new sort is that correct way ?
 
Upvote 0
Top