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
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Drawing Strings from Vector on ListField

I have a Vector consists of multiple Strings. I want that each string should be displayed on different row of listfield.

Here is the code I am using :

public void drawListRow(final ListField list, final net.rim.device.api.ui.Graphics g, final int index, int y, final int w)
{
Sample sample = (Sample)vtSample.elementAt(index);
Vector vt=sample.getSampleString();
String [] str=new String[vt.size()];
vt.copyInto(str);
for(int i=0;i<str.length;i++)
g.drawText(str[i], 5, y+10, 0, w);
}

 

Using above code, The strings are getting overlap on a single row of List. How to solve this problem?

Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Drawing Strings from Vector on ListField

drawListRow is used to draw a single row, it is called as often as there are elements in the listfield.
so don't use the iterator yourself, just let it be called by the framework.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: Drawing Strings from Vector on ListField

[ Edited ]

Thats what is my point.How cn i use strings in vector without iterating?

Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Drawing Strings from Vector on ListField

http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/ObjectListField.h... int)
retrieves the object from the current index.

and http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/ListFieldCallback... net.rim.device.api.ui.Graphics, int, int, int) gives you the current index.

that means you just use the index given as a parameter to retrieve the object and call drawText with it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter