Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
KDub
Posts: 7
Registered: ‎11-05-2008
My Device: Not Specified

ListField question

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.......

 

Category 1

.....name1

.....name2

.....name3

Category 2

......name 4

......name 5

 

Is this possible in a list or should I just use a treefield?

 

 

 

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: ListField question

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.

Please use plain text.
New Developer
KDub
Posts: 7
Registered: ‎11-05-2008
My Device: Not Specified

Re: ListField question

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.

 

 

 

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: ListField question

[ Edited ]

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.

 

like that:

 

 

myScreen.add(labelField1);
listField1.setCallback(callback1);
myScreen.add(listField1);

myScreen.add(labelField2);
listField2.setCallback(callback2);
myScreen.add(listField2);

....

myScreen.add(labelFieldN);
listFieldN.setCallback(callbackN);
myScreen.add(listFieldN);

Message Edited by tbilisoft on 11-09-2008 03:34 PM
Please use plain text.
New Developer
KDub
Posts: 7
Registered: ‎11-05-2008
My Device: Not Specified

Re: ListField question

That is a great idea.  I'm going to give that a try.  Thank you very much.
Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: ListField question

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).

 

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: ListField question

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,

 

String cl=r.m_class;
  int ix=0;
  Object o= hi.get(cl);
  if (o==null)
  { 
   ix=csz; ++csz;int mom= tf.addChildNode(0,cl);
   ix=mom; hi.put(cl,""+mom);
   ++id;
  }
  else ix=Integer.parseInt(o.toString());
  tf.addChildNode(ix,r);

 

 

Please use plain text.