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
RealCaracas
Posts: 15
Registered: ‎07-30-2009
My Device: Not Specified

Re: Customizing the background color for a ListField item

lol, sorry my mistake... I did copy and paste as fast as I could when you post the solution...

 

All is fixed now, I apply the methos for the MainScreen class...

 

Thank you very much!! 

Please use plain text.
New Developer
jacytan
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: Customizing the background color for a ListField item

Hi,

 

I am having the same problem.

When you set the background color of a row in the listfield, would the background color be on top of the "blue" highlight when the row is selected?

Because that is what happened to my application. 

Please use plain text.
Developer
RealCaracas
Posts: 15
Registered: ‎07-30-2009
My Device: Not Specified

Re: Customizing the background color for a ListField item

Hi, You will have to clear and redraw the elements on the field that is selected in the DrawListRow

 

if(list.getSelectedIndex() == index)  // DRAW ONLY WHEN THE OBJECT IS SELECTED

{   g.clear(); //VERY IMPORTANT

            //DO SOME DRAW (YOUR ELEMENTS ON THE FIELD)

            //FOR EXAMPLE SOME TEXT IN WHITE (SO IT CAN BE READ ON THE BLUE BACKROUND) 

 

       }

              else {   //NORMAL DRAW WHEN NOT SELECTED

                         //SOME TEXT IN BLACK (SOUPOSSING THAT YOU HAVE NOT OVERRIDE THE DEFAULT WHITE BACKROUND)   

               } 

 

Hopes it helps you... 

Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: Customizing the background color for a ListField item

 

One other thing I figured out in trying to get this to work is getSelectedIndex() returns 0 when nothing is selected. I used isFocus() to determine focus on the ListField and then set the selectedIndex to -1. This resolves the issue of the first row being highlighted by default.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

hi jlaprise,

 

i stuck at removing the default first row highlighting can you please help me with some sample code...

 

 

 

 

Please use plain text.
New Developer
braja
Posts: 11
Registered: ‎12-24-2009
My Device: Not Specified

Re: Customizing the background color for a ListField item

I was having lots of issues with the logic of changing the background color based on the focused row. Then I came across a solution from this other thread

 

Use the following if statement to find out if the current row being drawn is focused or not:

 

if(graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))

 

 

 

Please use plain text.
Developer
Kenjkelly01
Posts: 64
Registered: ‎01-12-2009
My Device: Blackberry Storm, Curve, Tour

Re: Customizing the background color for a ListField item

Thanks braja,

 That one line fixed my similar problems.  I was setting the text color in drawListRow(), which caused rows with Focus to be hard to read. Checking for that to avoid setting the font color, which will focus will have set to the opposite already, fixed it. 

Ken J Kelly
Please use plain text.
Developer
Kenjkelly01
Posts: 64
Registered: ‎01-12-2009
My Device: Blackberry Storm, Curve, Tour

Re: Customizing the background color for a ListField item

[ Edited ]
 
Ken J Kelly
Please use plain text.
Developer
ronenfe
Posts: 77
Registered: ‎06-03-2009
My Device: Not Specified

Re: Customizing the background color for a ListField item

[ Edited ]

to prevent the selection of the first row by default , i finally used this hack:

 

...
int firsttime = 0; // member
public void drawListRow(ListField list, Graphics g, int index, int y, int w) // draw row
{
int height = g.getFont().getHeight();
int width = Display.getWidth();
int selectedItem = list.getSelectedIndex();
// hack to prevent the selection on the first row
if (index == 0 && firstTime < 2)
{
selectedItem = - 1;
firstTime ++;
}

if(selectedItem == index)
{
g.clear();
g.setColor(Color.BLUE);
g.fillRect(0,y,Display.getWidth(),height*300/100);
g.setColor(Color.WHITE);
}
else
{
g.setColor(Color.LIGHTGREY);
g.fillRect(0,y,Display.getWidth(),height*300/100);
g.setColor(Color.BLACK);
}
...

it happens that 2 times upon loading the listfield the function enters with selectedItem equal to 0 , so this bypasses those two times.

 

I also used the overridings realcaracas posted in the previous page to prevent multiple selections when a key is down.

i had to do one more hack there to select first row when the down arrow is pressed, and to prevent user from going to the next field when last row is selected and he press the down arrow key:

 

 

   protected boolean navigationMovement( int dx, int dy, int status, int time ){

        invalidate();
        if (listSettings.getSelectedIndex() == 2 && dy > 0)
        	return true;
        else if (firstTime == 2 && listSettings.getSelectedIndex() == 0 && dy > 0)
        {
        	firstTime ++;
        	listSettings.setSelectedIndex(0);
        	return true;
        }
        return super.navigationMovement( dx, dy, status, time );

    }

 

 

 

 

 

 

 

Please use plain text.
Developer
ronenfe
Posts: 77
Registered: ‎06-03-2009
My Device: Not Specified

Re: Customizing the background color for a ListField item

[ Edited ]

there is an issue i can't resolve. On devices with trackwheel and not trackball, when i scroll, the previous selected row stays selected, so multiple rows get selected, navigationmovemnt only fires when i'm reaching beyond the last row or above the first row. How can i catch the tracking wheel event?

 

edit:

I found a fix to this very annoying problem:

 

http://supportforums.blackberry.com/t5/Java-Development/NavigationMovement-not-working-8700-trackwhe...

 

 

Please use plain text.