I think the problem here has to do with the fact that your code uses a BitmapField
to produce a background. I would suggest a couple other ways to do it, that will fix your row focus problem.
1. If The Background Must Be A Bitmap
Sometimes, this is necessary. If you have a complicated background design, or special gradient, you may need a background image. For that, I would still remove your BitmapField
. So, remove this code:
final Bitmap bck;
bck = Bitmap.getBitmapResource("inner-back-stripe.jpg");
BitmapField backgrnd = new BitmapField(bck,BitmapField.FOCUSABLE){
do not call add(backgrnd)
, and then in your sublayout()
method, remove this:
Field field = getField(0);
layoutChild(field, 640, 166);
setPositionChild(field, 0, 0);
and finally, remember to change the field index values in the sublayout()
method that lays out the other fields (index 1-6 -> 0-5).
Then, create your bitmap background with one extra line of code in your list's constructor:
public LeaveDetails(){
super(0, ListField.MULTI_SELECT);
setRowHeight(100);
setEmptyString("", DrawStyle.HCENTER);
setCallback(this);
setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("inner-back-stripe.jpg")));
Now, that will create a background for the entire ListField
, not just one row. But, in your case, that should work, as your background is just a solid green color.
2. Avoiding Bitmaps Completely
In your situation, I would not recommend a bitmap at all. You're using extra space in your app, and probably hurting performance (slightly) by using a bitmap, when all you want is a solid color background. So, remove the code I told you to remove above, and instead of the setBackground()
call I showed in the last code snippet, use this:
public LeaveDetails(){
super(0, ListField.MULTI_SELECT);
setRowHeight(100);
setEmptyString("", DrawStyle.HCENTER);
setCallback(this);
setBackground(BackgroundFactory.createSolidBackground(0xBDCE66));
0xBDCE66
looks like the hex color code for the green you showed in your question.
Row Separators
In your original question, you also showed white separator bars between the rows. My first two solutions won't give you that. But, you can add separators easily to either, by adding a few lines to the drawListRow()
method:
public void drawListRow(ListField listField, Graphics g, int index, int y,int width) {
LeaveDetails list = (LeaveDetails) listField;
TableRowManager rowManager = (TableRowManager) list.rows
.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
// draw a separator of a given color (e.g. white)
int oldColor = g.getColor();
g.setColor(Color.WHITE);
int h = getRowHeight();
//g.drawLine(0, y+h-1, width, y+h-1); // for 1 pixel thick line
g.fillRect(0, y+h-3, width, 3); // for 3 pixel thick "line"
g.setColor(oldColor);
}
Results
Note: the right side of each row is hidden because I tested this on a 360px wide screen, and your code hard-codes field locations. So, they're off the right side of the screen. This has nothing to do with the focus highlighting problem, though.