Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
JosuB
Posts: 9
Registered: 09-21-2009
Accepted Solution

Double line objectlistfield

I've got an objectlistfield which shows a bunch of selectable items which can be selected. The problem with it is that each items text is very long and needs at least two lines and the objectlistfield seems not to support this feature. It just cuts the text.

 

I tried increasing each rows height but the text does not change it's format. I've read that a possible solutions could be to overwrite the "drawListRow" from the objectlistfield but i cannot figure how to do that correctly.

 

I'll appreciate any kind of help.

Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: Double line objectlistfield

first, you have to set the row height. I usually take double the font size and add 2 for good measure.

now you can adjust the drawListRow. You get an y parameter that determines where in your current row you are. drawText takes both x and y as input. you can draw the first line using drawText(5,y,text) and the second using drawText(5, y+listField.getRowHeight/2, text2). You have to take care of a correct linebreak etc, i usually do this with a StringTokenizer.

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

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.
New Developer
JosuB
Posts: 9
Registered: 09-21-2009

Re: Double line objectlistfield

I this is waht you mean, right? My doubt now is how can I access to  FIRST_LINE_TEXT and SECOND_LINE_TEXT?

 

 

listaPtos = new ObjectListField()
		{		
			public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) 
			{
				graphics.drawText(FIRST_LINE_TEXT, 5, y);
				graphics.drawText(SECOND_LINE_TEXT, 5, y + listField.getRowHeight() /2 );
			}
			
		};

 Thanks for your fast reply!

 

Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: Double line objectlistfield

i don't work with the standard listfield anymore, using an own implementation that makes things easier.

anyhow, you have the listfield and the index, thus you can retrieve the object that should be drawn. you can read its attributes or, if it is a string, handle it directly.

 

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

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.
Developer
davidmccormack
Posts: 168
Registered: 11-01-2008
My Carrier: Meteor (Ireland)

Re: Double line objectlistfield

That should work, though I would probably calculate the increase in Y for the second call to drawText() by adding graphics.getFont().getHeight() instead of what you're doing.

 

Another observation I'd have is that you should avoid hardcoded pixel counts like the 5 you have for X or the 2 that the other reply suggested as padding. The reason is that font sizes vary quite dramatically between different devices so your spacing should always be calculated in proportion to the font size if you want the layout to look consistent between different devices.

 

I'm not really sure what you mean about getting access to the first and second line. Do you mean, how do you actually get the text for the current list item? You just use the index that's passed to drawListItem() and invoke get() on the ObjectListField.

Please use plain text.
New Developer
JosuB
Posts: 9
Registered: 09-21-2009

Re: Double line objectlistfield

Thanks everybody I could solve my issue. I had problems using font height so I finally used the Y parameter.

Please use plain text.