Android Question Sort List of Strings with Localization

Cainsoft

Member
Licensed User
Longtime User
Hi Erel,

I would like to sort below List of strings as per user locale.
For different user locale sort output should be different as per there locale.

"Äbc", "äbc", "Ábc", "ábc", "Abc", "abc", "ABC, etc."


I have found a soluiton for this on stackoverflow website:

-------------------------------------------------------------

List<String> words = Arrays.asList(
"Äbc", "äbc", "Ábc", "ábc", "Abc", "abc", "ABC"
);


Collator coll = Collator.getInstance(locale);
coll.setStrength(Collator.PRIMARY);
Collections.sort(words, coll);

------------------------------------------------


How can I implement this in B4A ?

Thanks,
Attila
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is a community forum. Please don't limit your questions to a single member.

B4X:
Sub SortListWithDeviceLocale(l1 As List)
   Dim collator As JavaObject
   collator = collator.InitializeStatic("java.text.Collator").RunMethod("getInstance", Null)
   collator.RunMethod("setStrength", Array (0))
   Dim jo As JavaObject
   jo.InitializeStatic("java.util.Collections").RunMethod("sort", Array(l1, collator))
End Sub
 
Upvote 0
Top