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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

How to make a Vector for ListField hold more than one column

not really a Blackberry problem more of a java.

 

I have a list field and and use a callback to manage it. The problem i have is now I make the list filed 2 columns but i can only figure out how to put one field in the vector

 

private ListField _itemListField;         
private Vector _itemListVector = new Vector();
_itemListVector.addElement( firstColumnItem );
_itemListField.setSize( _itemListVector.size() );  // causes the list to be updated and painted

 

can someone provide some suggestions on how to add the secondColumnItem ?

Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: How to make a Vector for ListField hold more than one column

Well I found an way around my problem. rather than store everything in the vector, I just open the obejct where the data is stored and match it to the row value in the vector then list the columns as needed.

 

Probably not the best way to do things but its working.

 

I would still like to know how to make a multi-column vector work...

Developer
Posts: 26
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to make a Vector for ListField hold more than one column

Using two vectors, one for each row.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to make a Vector for ListField hold more than one column

I think you have answered your own question with your comment "and match it to the row value in the vector".

 

Did you think about just putting the Object in the Vector?  For example, if you have a Customer object that has a first name or a second name, then you just at the Customer Object to the Vector.

 

Here is a more specific example, sorry this was just coded by hand, not tested, designed to show the process only.

 

// Following adds an object containing two values (in this case Strings) // to the Vector, and notes the index the Object was added at. String [] twoColumnString = new String [] {"First name", "Second Name"}; Vector v = new Vector(); v.addElement(twoColumnString); int twoColumnStringIndex = v.size()-1; ... // at some other point, this object can be extracted // and the two Strings recovered ... Object extractedObject = v.elementAt(twoColumnStringIndex); String [] extractedColumns = (String []) extractedObject; String firstName = extractedColumns[0]; String secondName = extractedColumns[1]; ... // If your Vector contains multiple different Objects // then you can check the extracted Object using instanceof, // for example if ( extractedObject instanceof (String []) ) { // There is some debate about the efficiency of doing this // everytime verses catching a ClassCastException

 

 

I would recommend you invest in a Java book, it will explain this sort of thing.