Android Question [solved] using list.sortType with a class instead of a type

Dave O

Well-Known Member
Licensed User
Longtime User
I have a list of objects that are all based on a class, not a type.

I need to sort this list by one of the class fields. If this was a type (not a class), I could just use the list's sortType function.

I was hoping this would also work with a class (because it's arguably a more capable type), but it generates a compile error (NoSuchFieldException).

In this case, my class is very simple, so I could just demote it to a type so I can use sortType, but I wonder if it's possible to upgrade B4A to let sortType work with class fields as well as type fields?

Or is there another way to do this?

Thanks!
 

stevel05

Expert
Licensed User
Longtime User
Try prefixing the field name with an underscore and making the name lower case. So if your field is called Field use _field.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
Hey @stevel05 , that did the trick, thanks!

FYI, I did find out that if you use sortType, it works fine with numbers. However, if you use sortTypeCaseInsensitive, it treats numbers as strings, so "10" gets sorted before "2".

Thanks again!
 
Upvote 0
Top