Android Question Trouble with Sort List by Type

mw71

Active Member
Licensed User
Longtime User
Hi,

i read a CSV List with StringUtils.LoadCSV, transfer it into a other List with Custom Type an sort it.

B4X:
    'Declare in Process_Globals in B4A, Class_Global in B4J
    Type SBWBerge (berg As String,Ref As String,wp As String)

    
    'Code to read and Sort
    Private Bergliste_in As List
    Bergliste_in = su.LoadCSV(File.DirAssets,SBW_Bergliste,";")

    Dim Bergliste_Sort As List
    Bergliste_Sort.Initialize
    For z=0 To Bergliste_in.Size-1
        Dim Berge As SBWBerge
        Dim tmpDaten() As String = Bergliste_in.get(z)
        Berge.berg=tmpDaten(0).Trim
        Berge.Ref=tmpDaten(1).Trim
        Berge.wp=tmpDaten(2)
        Bergliste_Sort.Add(Berge)
    Next
    Bergliste_Sort.SortTypeCaseInsensitive("berg",True)

my problem is, that the first insert in the List is move to the last Place in the sortet List, but it must the First.
(e.g. the Sort Result is
B
C
D
A)
 

Mahares

Expert
Licensed User
Longtime User
my problem is, that the first insert in the List is move to the last Place in the sortet List, but it must the First.
Your code looks correct. Perhaps, you may want to export the text file or portion of it, so someone can test it
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Are you sorting, numbers, letter or both in your column?
I could be completely wrong here, but I'm under the illusion that whatever you are sorting must only be of a set type, so that means numbers only, letters only but NOT mixed.
 
Upvote 0

Quandalle

Member
Licensed User
The initialization "Berge.initialize" is missing after the dim
Then if it persists, you have to isolate the problem. For example, check that the sorting works without reading the values from the CSV but by initializing them in the code, etc...
B4X:
Sub Process_Globals
    Type SBWBerge (berg As String,Ref As String,wp As String)
    
End Sub

...
Dim Bergliste_Sort As List
    Bergliste_Sort.Initialize
    Dim value()  As String = Array As String ("A2","Z","c","e","a1")
    For Each s As String In value
        Dim Berge As SBWBerge
        Berge.Initialize
        Berge.berg=s
        Berge.Ref=s
        Berge.wp=s
        Bergliste_Sort.Add(Berge)
    Next
    Bergliste_Sort.SortTypeCaseInsensitive("berg",True)
    Log(Bergliste_Sort)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
insert "Berge.initialize", no change :-(
I made a small project using this as text file and got it to work just fine. You need to attach a copy of your text file or portion of it:
tunisia; Tunis; Africa
Germany; Berlin; Europe
Egypt; cairo; africa
Japan; tokyo; Asia
france; paris; europe
australia; sydney; australia
Brazil; Brasilia; America
chile; santoago; america
Russia; Moscow; Europe
Lebanon; Beyrouth; Asia
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
Can you log an asc(first char of your elements)?
no problem, now i see (but dont understand) that the first char of the String what ist move to the end is 65279, exepted is 65 (A)

-> Google -> Youtube -> Change the Coding from UTF-8-BOM to UTF-8, now it works.

Thanks to all!!!
 
Last edited:
Upvote 0
Top