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
Developer
ipcTony
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 ?

Please use plain text.
Developer
ipcTony
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...

Please use plain text.
Developer
bwei
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.
Please use plain text.
Developer
peter_strange
Posts: 19,601
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.

Please use plain text.