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
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel
Accepted Solution

Line is not coming after each row in list

Hi,

 

I am showing a list in my current application. In the list, i am drawing a line after each row. Just one line of string i am adding in each row. Now When i am checking the list, in some devices, lines are coming. Like in Bold 9790, after each row, one line is added. But in Torch 9810 and Curve 9320, line is not there. I am not getting why this different behavior for different devices.

 

Can any one please help.

 

Here is my code:

 

public class ListCallBack implements ListFieldCallback{

		
		public void drawListRow(ListField listField, Graphics graphics, int index,
		        int y, int width) {
			
		    String text = "xxxxxxx";
		    graphics.setFont(FONT_FAMILY_1_SF_AS_08);
		    graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS, width);

		    if (index != 0) {
		    	graphics.setColor(Color.BLACK);
		    	graphics.drawLine(0, y-12, width, y-12);
			}
		}

		public Object get(ListField listField, int index) {
		    // TODO Auto-generated method stub
		    return mAccounts[index];
		}

		public int getPreferredWidth(ListField listField) {
		    // TODO Auto-generated method stub
		    return screenWidth;
		}
		
		public int getPreferredHeight() {
			return getContentHeight();
		}

		public int indexOfList(ListField listField, String prefix, int start) {
		    // TODO Auto-generated method stub
		    return listField.getSelectedIndex();
		}

		}
}

 Thanks..

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Line is not coming after each row in list

check the rowheight of the listfield.
maybe y-12 is not visible?
----------------------------------------------------------
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
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Line is not coming after each row in list

If you have not deliberately specified the row height, then the actual height may vary by device, depending on Font sizes and on touch screen devices, the ListField may be larger so as to accommodate fat fingers.

 

But the important issue here is that in your drawListRow when you are passed in the variables

(ListField listField, Graphics graphics, int index, int y, int width)

you should only paint the rectangle given by

0, y, width, listField.getRowHeight()

 

So you should NOT paint at y-12.  That is outside of your row. 

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Line is not coming after each row in list

I have tried with this. But still not getting the best Result.

 

Font f = FONT_FAMILY_1_SF_AS_08;
 graphics.setFont(f);
 int h = f.getHeight() + 1;
graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS, width);
graphics.setColor(Color.BLACK);
graphics.drawLine(0, y + h, width, y + h);

 

 

So i think best option setting the List Row Height in this case. Because in BB 9300, height of each row easy pretty small.

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Line is not coming after each row in list

I have no idea what you mean by 'best result'.

 

To make sure the separator line always appear at the bottom of the row, you could try the following.

 

int h = listfield.getRowHeight() - 1;

graphics.setColor(0); // Black

graphics.drawLine(0, y + h, width, y + h);

Please use plain text.
Developer
arindamhit
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Line is not coming after each row in list

The Best result i meant, the variable row height for device to device. So presently i am using the Row Height and made the changes Accordingly.

 

Here is my Code :

 Font f = FONT_FAMILY_1_SF_AS_08;
		    graphics.setFont(f);
		    int h = f.getHeight();
		    int height = (listField.getRowHeight() - h)/2 ;
		    y += height;
		    graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS, width);
		    if (index != 0) {
		    	graphics.setColor(Color.BLACK);
		    	graphics.drawLine(0, y - height + 1 , width, y - height + 1);
			}

 It has worked properly. Thanks a lot Peter and Simon.

Please use plain text.