Android Question list sort custom type

drgottjr

Expert
Licensed User
Longtime User
is there some way to populate a list of custom type, similar to the way one can populate a list or an array with 1 statement, eg:
<code>
dim array() as string = array as string("erel", "george", "foo", "bar")
</code>

this is implied in list.addall(), but i'm not getting it to work with a custom type. the reason i'm using a custom type is because i want to sort the list later using a sort field. i started out with a map, but erel said to change to a list with a custom type and to chose a sort field. but i'm not getting the initial setup right.

so after an initial setup
<code>
Type customtype( name as string, id as int )
dim customtypelist as list
customtypelist.initialize
</code>

i'd like to be able to do something like this:
<code>
dim ct as customtype("erel", 1)
customtypelist.add( ct )
</code>

or like this:
<code>
dim ct as customtype = ("erel", 1)
customtypelist.add(ct)
</code>

or like this (best choice!)
<code>
customtypelist.addall( ("erel",1), ("george",2), ... )
</code>

what irks me is having to do it this way:
<code>
dim ct as customtype
ct.initialize
ct.name = "erel"
ct.id = 1
customtypelist.add(ct)
</code>

then cutting and pasting and editing the name and id for the remainder of the list one by one.
do i have to write a class to do any of the above? if any of my 3 preferences above is, in fact, doable,
i'm missing something in the execution.

thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
please use code tags when posting code. code tags does NOT uses <>... Use []

You dont need to do it manually

codetag001.png

codetag002.png

codetag003.png
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
thanks. i guess i wasn't clear regarding what i'm looking for: i'm trying to go down a level, not add one. the little sub essentially is the same as manually creating an instance of a custom type - but wrapped in a sub. (admittedly, it does save cutting and pasting.) i'm looking for a list type's method that does this (and presumably optimized).

and, of course, what i'm really looking for is list.addall( my_list_of_custom_type_instances ) just like it does for list.addall( list as list ). i'm trying to do that, but i must be doing it wrong. someone has gone to the trouble of extending the list type to include the sorttype property to handle the fields in a custom type, yet not allow for the list of custom types to be added to the list with list.addall(). i could do all the steps necessary in basic and then wrap it in a sub, but before inventing the wheel again i'm asking if this already exists, and if it does, what is the proper syntax. is the only way to build a list of custom type by hand, ie, list.add( custom_type instance ) ? or is there a way to do it with list.addall() ?
 
Upvote 0
Top