11-08-2008 12:15 AM
I have a sorted Vector holding some object. Each object has two fields.....name and category. I want my list to display the objects by category. Kind of like this.......
Is this possible in a list or should I just use a treefield?
11-08-2008 09:13 AM
If you wish to display data as you described it would be better to use TreeField class.
With ListField it can be done, but the implementation won't be elegant.
You may add a LabelField to the screen for each category title and ListField instance after LabelField for this category contents. This way won't let you navigate the list freely, i.e expand/collapse categories.
TreeField is better in this case.
11-09-2008 10:12 AM
actually, this sounds like it would work for me. Im not interested in collapsing on the category. If I add a lablefield, I assume each lablefield would be its own row? My only concern would be that my row index is also used to determine which element of a object vector is being inserted into the list. If I write a lable into the list, I would be skipping that specific object. Sorry if this doesnt make any sense.
11-09-2008 10:24 AM - edited 11-09-2008 10:34 AM
In case you want to use many ListField instances separated via LabelFields use separate ListFieldCallback instances attached to each ListField instance. In this case you'll control every list field as you described.
And please note that you're adding LabelField instances to the Screen instance not to the ListField instance.
It is possible to add many fields to the one screen. You can add several ListField instances and separate them via LabelFields.
11-09-2008 12:12 PM
What does the independent listfield approach offer over treefield?
I've never used treefield but I do have a folder
based system that navigates purely with menuitems- this turned out to be easy and flexible enough for me.
The menuitems just represent each thing you want to display, as well as an "up" option to go up a level.
There is almost no overhead with this approach if you can live with the limitations- just call Menu(), addItem's,
and then wait for a selection to be made ( menuitem run method does nothing in my situation).
If you expect to be doing a lot of reorganizing, I've found the RIM Arrays methods to be helpful. They only seem to operate on arrays so I've converted all my lists and data structures to be array based, not vector based. So far this looks like it will work as I intend to collect a variety of lists that serve as operands for various processing methods.
I can retain indicies, such as proximity to arbitrary origins, as needed in a reasonably consistent way ( don't have to worry about indicies and targets getting out of sync etc).
11-09-2008 03:53 PM
I just did a treefield for a related application- I have a bunch of points of interest and wanted collapsable
folders for each catagory- streams, schools, churches, etc- it works fine except that scrolling off the
end resulted in death by NPE- if I override the movefocus method it seems to work just fine. Is there a
trick to telling it zero means zero? AFAIK, the hierarchy is OK as the catagories are right and
the instances, which came off of a database, seem right. I normally test high-risk stuff with controlled data
but the display makes sense ( all points of interest where I grew up, cemetaries are listed under the cemetary catagory, etc). It seems odd that proper usage wouldn't handle end of list scroll events.
I have a hashtable "hi" for known classes and record the parent node for this class( I use strings intead of Integer just for ease, it seems dumb to encapsulate a primitive type here) . "r" is the thing I'm adding
as a member of its class folder. "tf" is the treefield,
Object o= hi.get(cl);
ix=csz; ++csz;int mom= tf.addChildNode(0,cl);