12-04-2012 05:36 AM
Looks OK, but the proof is in the pudding as they say - so does it work?
12-04-2012 06:03 AM
12-04-2012 06:28 AM
The best place to start when explaining how things work is the documentation - have you looked up the methods used in the supplied code to see what it is doing? Which parts do you not understand?
Regarding creating code for you - sorry I don't have time to do specific things like this and besides you get paid for that not me! What you are asking for is a variable number of columns, and as has already been pointed out, that is just dividing the width you have by the number of columns you want to display, then painting the columns. The code you already have on this Thread is a pretty good sample for you
BTW, it has been suggested that to calculate the width of the columns, you use Display.getWidth(). Don't. Use the width that gets passed in to drawListRow().
12-04-2012 06:31 AM
12-04-2012 06:59 AM
12-04-2012 09:22 AM
What do you currently see? Can you figure out why you see it?
12-04-2012 11:48 AM
Hello sir ..i see Gray color due to alpha to to override draw method..?
protected void drawFocus (Graphics graphics, boolean on)
{
XYRect rect = new XYRect();
graphics.setGlobalAlpha(150);
getFocusRect(rect);
drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,rect.x,rect.y,rect.width,rect.height);
}
i need defult blue color on focus of row..can it is possible..?
12-04-2012 01:57 PM
"I see Gray color due to alpha to to override draw method..?"
I would agree, and to check you could change this method and see if you are correct!
The problem you have is that you are setting the background color. The ListField expects that you will just paint over its current background. Then to indicate focus it paints the blue background. If you wish to retain that behavior, then you can not set the background when you are painting the focused row.
This is not the way I do it (my method is slightly more complicated), but I think the easiest way to do this is to set a flag in drawFocus, call super.drawFocus, reset the flag when the super.drawFocus returns. Then in your drawListRow method, check to see if this flag is set, and if so, don't set the background color.
Give this a go, and let us know how you get on.
12-05-2012 12:09 AM
Hello
i do like this ....
first i declare hasfocus varible .then i enter in
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
int curSelected;
if(!hasFocus){
if(index%2 == 0){
graphics.setColor(Color.RED);
graphics.fillRect(0, y, width, listField.getRowHeight());
graphics.setColor(Color.WHITE);
}else{
graphics.setColor(Color.BLACK);
graphics.fillRect(0, y, width, listField.getRowHeight());
}
}
//graphics.fillRect(0,0,width,y);
int xpos = 0;int ypos = 0;
graphics.setFont(Font.getDefault());// please set a font value
// this is first column text
graphics.setColor(Color.PINK);
graphics.drawText("column1"+index,xpos,y);
xpos += columnWidth;
//graphics.setColor(Color.RED);
graphics.drawText("column2",xpos,y);
xpos += columnWidth;
graphics.drawText("column3",xpos,y);
xpos += columnWidth;
graphics.drawText("column4",xpos,y);
}
what i have to do in this code ? can you explain ?
protected void drawFocus(Graphics graphics, boolean on) {
//hasFocus = true;
super.drawFocus(graphics, on);
//hasFocus = false;
// XYRect rect = new XYRect();
// graphics.setGlobalAlpha(200);
// getFocusRect(rect);
// drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true, rect.x,rect.y,rect.width,rect.height);
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
}
// Invoked when a field loses the focus.
public void onUnfocus() {
hasFocus = false;
super.onUnfocus();
invalidate();
}
12-05-2012 04:22 AM - edited 12-05-2012 04:23 AM
I had not expected you to add onFocus or onUnfocus methods. All I expected was this:
protected void drawFocus(Graphics graphics, boolean on) {
hasFocus = true;
super.drawFocus(graphics, on);
hasFocus = false;
}