07-30-2009 12:38 PM
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!!
08-13-2009 01:50 AM
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.
08-13-2009 10:45 AM
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...
12-09-2009 03:43 AM
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...
12-31-2009 12:57 AM
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))
02-04-2010 11:28 AM
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.
02-04-2010 11:30 AM - edited 02-04-2010 11:31 AM
03-19-2010 12:05 PM - edited 03-19-2010 05:00 PM
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 );
}
03-26-2010 11:54 AM - edited 03-26-2010 12:15 PM
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: