Sorting Items in a listView

walterf25

Expert
Licensed User
Longtime User
Hi guys, i was wondering if there's any way to sort the items in a ListView, for example if I have a list with different numbers and they are not in order, how can i sort the items in the list from lower to highest number?

any ideas?

thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
If the ListView is a Single Line you could load the content to a LIST, sort the list and re-populate the ListView.


I understand that, but i'm trying to come up with the code to actually sort the items in order from lowest to highest number. How can i do that?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Don't exactly undestand your question, but to sort the LIST you just have to do this:
B4X:
MyList.Sort(True)

Look at the attached sample.
 

Attachments

  • ListSortSample.zip
    6.7 KB · Views: 694
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
B4X:
Dim MyListView As ListView
Dim List1 As List
list1.Initialize
   
For l = 0 To 100
   list1.Add("Your data here.." & (100-l)) 'Data and number high to low
Next 
list1.Sort(True) 'puts them in order low to high
For l = 0 To 100
   MyListView.AddSingleLine(list1.Get(l))
Next
'Your listview is now sorted
 
Upvote 0
Top