我正在开发一个使用表格行管理器来创建表格视图的黑莓应用程序。在我的应用程序中,我添加了位图字段作为行背景,然后字段突出显示的默认蓝色消失了。我在 stackoverflow 中阅读了一些答案并实现了此代码以尝试使其以默认颜色突出显示:
//Adds background image
final Bitmap bck;
bck = Bitmap.getBitmapResource("inner-back-stripe.jpg");
BitmapField backgrnd = new BitmapField(bck,BitmapField.FOCUSABLE){
protected void drawFocus(Graphics graphics, boolean on)
{
setSpace(5, 5);
super.drawFocus(graphics, on);
}
};
但仍然有同样的问题,行没有突出显示,滚动时只有文本变为白色。
示例行背景:
在这里,我粘贴了我使用过的整个代码
public class LeaveDetails extends ListField implements ListFieldCallback {
TableRowManager row;
Vector rows;
private String[] arrdNames = {"Udith","Mohammadu","Rajaram","David"};
private String[] arrDate = {"12-Jan-2013","17-Feb-2013","20-Mar-2013","14-May-2013"};
private String[] arrType = {"Medical Leave","Annual Leave","Medical Leave","Annual Leave"};
private int[] arrCount = {3,5,2,6};
public LeaveDetails(){
super(0, ListField.MULTI_SELECT);
setRowHeight(100);
setEmptyString("", DrawStyle.HCENTER);
setCallback(this);
rows = new Vector();
for (int x = 0; x < 4; x++) {
row = new TableRowManager();
//Adds background image
final Bitmap bck;
bck = Bitmap.getBitmapResource("inner-back-stripe.jpg");
BitmapField backgrnd = new BitmapField(bck,BitmapField.FOCUSABLE){
protected void drawFocus(Graphics graphics, boolean on)
{
setSpace(5, 5);
super.drawFocus(graphics, on);
}
};
row.add(backgrnd);
//BitmapField backgrnd = new BitmapField(Bitmap.getBitmapResource("inner-back-stripe.jpg"),Field.FOCUSABLE);
//row.add(backgrnd); //Field 0
//Adds names
LabelField lfName = new LabelField(String.valueOf(arrdNames[x]),FIELD_HCENTER);
lfName.setFont(lfName.getFont().derive(Font.BOLD,30));
row.add(lfName);//Field 1
//Adds date
LabelField date = new LabelField("Applied on : "+arrDate[x]);
row.add(date);//Field 2
//Adds type
LabelField type = new LabelField("Leave type : "+arrType[x]);
row.add(type);//Field 3
//Adds duration in numbers
LabelField lfCountNotifications = new LabelField(String.valueOf(arrCount[x]),FIELD_HCENTER);
lfCountNotifications.setFont(lfCountNotifications.getFont().derive(Font.BOLD,72));
row.add(lfCountNotifications);//Field 4
//Adds word "Duration"
LabelField lfNewNotification = new LabelField("Duration/Days",Field.FIELD_HCENTER);
lfNewNotification.setFont(lfNewNotification.getFont().derive(Font.GEORGIAN_SCRIPT,30));
row.add(lfNewNotification);//Field 5
//Adds right arrow image
BitmapField showMore = new BitmapField(Bitmap.getBitmapResource("more.png"));
row.add(showMore);//Field 6
//Adds rows to the table
rows.addElement(row);
}//End of the for loop
setSize(rows.size());
}
// ListFieldCallback Implementation
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());
}
//Tracks field click event
protected boolean trackwheelClick(int status, int time)
{
int index = getSelectedIndex();
switch (index) {
case 0: Dialog.inform(index+" Clicked");
break;
case 1: Dialog.inform(index+" Clicked");
break;
case 2: Dialog.inform(index+" Clicked");
break;
case 3: Dialog.inform(index+" Clicked");
break;
default: Dialog.inform("Error!");
break;
}
return true;
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
// Causes the fields within this row manager to be layed out then
// painted.
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
// Place this row manager within its enclosing list.
setPosition(x, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
g.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(g);
// Restore the graphics context.
g.popContext();
}
// Arrages this manager's controlled fields from left to right within
// the enclosing table's columns.
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
//Field background image
Field field = getField(0);
layoutChild(field, 640, 166);
setPositionChild(field, 0, 0);
// Name
field = getField(1);
layoutChild(field, 640, fontHeight+4);
setPositionChild(field, 0, 5);
// Date
field = getField(2);
layoutChild(field, 500, fontHeight+4);
setPositionChild(field, 0, 30);
//Type
field = getField(3);
layoutChild(field, 500, fontHeight+1);
setPositionChild(field, 0, 60/*fontHeight+6*/);
//Duration number
field = getField(4);
layoutChild(field, 100, 100);
setPositionChild(field, 450, 5);
//"Duration" word
field = getField(5);
layoutChild(field, 300, 100);
setPositionChild(field, 400, 62);
//More image
field = getField(6);
layoutChild(field, 100, 100);
setPositionChild(field, 575, 20);
setExtent(preferredWidth, getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return 640;
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
有没有人知道这里发生了什么?我想让它以默认的蓝色突出显示。我对黑莓非常陌生。