iOS Question Sort array

Graeme M itchell

Member
Licensed User
I am trying to sort the ListPart list. I tried listpart.sort(true) but it errors out. I checked the whole list to see if there were any anomalies but they are all numbers (2-4 digit)

B4X:
Sub FillArray(Search As Int)

  
If Search < 99 Then
   partsList = su.LoadCSV(File.DirDocuments, "Database.txt", TAB)
   Dim MyArray (partsList.size,24) As String
   listpart.Initialize
       lastx = partsList.Size -2
   For i=0 To partsList.Size -2
       Dummy = partsList.Get (i)
       For j= 0 To 24
           MyArray (i,j)= Dummy(j)
       Next
       listpart.Add(cs.Initialize.Font(fnt).Append(MyArray(i,Search)).PopAll)
  
   Next
  
   SearchIndex = Search  
   PickerPart.SetItems(0,listpart)
   PickerPart.SetRowsHeight(40)
End If

End Sub
 

Graeme M itchell

Member
Licensed User
The sort was just about the SearchIndex = Search line

B4X:
listpart.sort(true)
SearchIndex = Search  
PickerPart.SetItems(0,listpart)
PickerPart.SetRowsHeight(40)
[\code]

Application_Start
Application_Active
DatabaseFile Was Download
Error occurred on line: 157 (Database)
-[NSConcreteMutableAttributedString compare:options:]: unrecognized selector sent to instance 0x14751470
Stack Trace: (
  CoreFoundation       <redacted> + 152
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 696
  CoreFoundation       _CF_forwarding_prep_0 + 24
  PartsDatabase        __17-[B4IList sort::]_block_invoke_2 + 98
  CoreFoundation       <redacted> + 50
  CoreFoundation       <redacted> + 146
  CoreFoundation       <redacted> + 146
  CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       <redacted> + 146
 CoreFoundation       CFSortIndexes + 402
 CoreFoundation       <redacted> + 316
 CoreFoundation       <redacted> + 74
 PartsDatabase        -[B4IList sort::] + 544
 PartsDatabase        -[B4IList Sort:] + 62
 CoreFoundation       <redacted> + 68
 CoreFoundation       <redacted> + 300
 PartsDatabase        +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
 PartsDatabase        -[B4IShell runVoidMethod] + 210
 PartsDatabase        -[B4IShell raiseEventImpl:method:args::] + 2042
 PartsDatabase        -[B4IShellBI raiseEvent:event:params:] + 1328
 PartsDatabase        +[B4IDebug delegate:::] + 52
 PartsDatabase        -[b4i_database _fillarray:] + 420
 PartsDatabase        -[b4i_database _show:] + 1384
 PartsDatabase        -[b4i_main _btnmat_click] + 430
 CoreFoundation       <redacted> + 68
 CoreFoundation       <redacted> + 300
 PartsDatabase        +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
 PartsDatabase        -[B4IShell runMethod:] + 588
 PartsDatabase        -[B4IShell raiseEventImpl:method:args::] + 2192
 PartsDatabase        -[B4IShellBI raiseEvent:event:params:] + 1328
 PartsDatabase        __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
 libdispatch.dylib    <redacted> + 10
 libdispatch.dylib    <redacted> + 22
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 902
 CoreFoundation       <redacted> + 8
 CoreFoundation       <redacted> + 848
 CoreFoundation       CFRunLoopRunSpecific + 470
 CoreFoundation       CFRunLoopRunInMode + 104
 GraphicsServices     GSEventRunModal + 80
 UIKit                UIApplicationMain + 150
 PartsDatabase        main + 106
 libdyld.dylib        <redacted> + 2
)
Class (b4i_httpjob) instance released.
 

Graeme M itchell

Member
Licensed User
So the command to create the OrderedMap is below but I am not sure how to implement this into my for next loop since I am only looking at the adding a numeric value which I assume is the value but what would be the key?

The first column in the partsList ir MyArray is a unique identifier but then I tried the code below to add that and I see the warning "Types do not match"

B4X:
From website
Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap2(Array("a", "b", "c", "d"), Array(1, 2, 3, 4))

My Code
Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap2(MyArray(i,0),MyArray(i,search))
 

Erel

Administrator
Staff member
Licensed User
Something like:
B4X:
Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap
 For i=0 To partsList.Size -2
       Dummy = partsList.Get (i)
       For j= 0 To 24
           MyArray (i,j)= Dummy(j)
       Next
       om.Put((MyArray(i,Search), cs.Initialize.Font(fnt).Append(MyArray(i,Search)).PopAll)
   Next
om.Keys.Sort(True)
   For Each s As String In om.Keys
       
listpart.Add(om.Get(s))
   Next
 
Top