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: 108
Registered: ‎08-05-2008
My Device: Not Specified
Accepted Solution

Trying to provide alternate row coloring on a ListField

I want to implement alternate row coloring on a ListField.  

 

I implemented ListFieldCallback on a ListField and in the drawListRow, I have the following:

 

 

public void drawListRow(ListField list, Graphics g, int index, int y, int w) { if(index % 2 != 0) { g.setColor(0xB2FFED); g.fillRect(0, y, w, list.getRowHeight()); g.setColor(0x000000); list.invalidate(index); } String text = (String)listElements.elementAt(index); g.drawText(text, 0, y, 0, w); }

 

This works, but it also paints the selected item with the color I set.  I want the selected item to continue to be painted with the system defined color.  I tried adding a check for list.getSelectedItem != index, but that does not seem to work very well.

 

Is there an example of what I want to do? 

 

Highlighted
Developer
Posts: 43
Registered: ‎09-28-2009
My Device: Not Specified

Re: Trying to provide alternate row coloring on a ListField

Hi rgelb1,

 

I think this KB Article How To - Create a colour ListField is what you are looking for, It explains how to draw certain fields with color while keeping highlighting seperate. I hope this helps, If not I will gladly assist you with the code needed.

 

Regards

 

Andre

Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: Trying to provide alternate row coloring on a ListField

[ Edited ]
According to my experience the best solution to paint fouced area properly is to check state of Graphics object (and make framework paint it for you). See some deatails in my post at another thread http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=55352#M55352
Message Edited by SergGr on 10-04-2009 11:56 PM

--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.