Please find the custom list field below. Use drawListrow for drawing the contents.
Code:
/*
* GLClubsListField.java
*
* © MOPL, 2003-2008
* Confidential and proprietary.
*/
package customfields;
import java.util.Enumeration;
import java.util.Vector;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
/**
*
* @author Praveen.
* @version 1.0
*/
public class GLClubsListField extends ListField implements ListFieldCallback {
private Vector _listData;
public GLClubsListField (Vector data) {
_listData = data;
setSize(_listData.size());
setSearchable(true);
setCallback(this);
setRowHeight(Font.getDefault().getHeight() + 12);
}
/*
protected void drawFocus (Graphics graphics, boolean on) {
XYRect focusRect = new XYRect();
int offset = 100;
if (Graphics.getScreenHeight() > 240) {
offset = 150;
}
graphics.setGlobalAlpha(150);
graphics.setColor(Color.BLUE);
getFocusRect(focusRect);
drawHighlightRegion(graphics, HIGHLIGHT_FOCUS, true, focusRect.x, focusRect.y,
focusRect.width, focusRect.height);
}*/
protected void drawFocus (Graphics graphics, boolean on) {
XYRect rect = new XYRect();
graphics.setGlobalAlpha(150);
graphics.setColor(Color.BLUE);
getFocusRect(rect);
drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,rect.x,rect.y,rect.width,graphics.getFont().getHeight() + 1);
}
public int moveFocus (int amount, int status, int time) {
this.invalidate(this.getSelectedIndex());
return super.moveFocus(amount, status, time);
}
public void onFocus (int direction) {
super.onFocus(direction);
}
protected void onUnFocus () {
this.invalidate(this.getSelectedIndex());
}
public void refresh () {
this.getManager().invalidate();
}
public void drawListRow (ListField listField, Graphics graphics, int index, int y, int width) {
String[] rowString = (String[]) _listData.elementAt(index);
graphics.setGlobalAlpha(255);
graphics.setFont(Font.getDefault().getFontFamily().getFont(Font.PLAIN, 24)); //17
int selectedIndex = getSelectedIndex();
if (selectedIndex == index) {
graphics.setColor(Color.BLUE);
} else {
graphics.setColor(Color.BLACK);
}
int clubOffset = 100;
if (Graphics.getScreenHeight() > 240) {
clubOffset = 150;
}
int x = 0;
graphics.drawText(rowString[1], x, y, DrawStyle.HCENTER, width);
//graphics.drawText(rowString, (0 - (clubOffset/2)), y, DrawStyle.HCENTER, width);
}
public Object get(ListField listField, int index) {
String rowString = (String) _listData.elementAt(index);
return rowString;
}
public int indexOfList (ListField listField, String prefix, int start) {
for (Enumeration e = _listData.elements(); e.hasMoreElements(); ) {
String rowString = (String) e.nextElement();
if (rowString.startsWith(prefix)) {
return _listData.indexOf(rowString);
}
}
return 0;
}
public int getPreferredWidth(ListField listField) {
return 3 * listField.getRowHeight();
}
protected boolean trackwheelClick (int status, int time) {
invalidate(getSelectedIndex());
return super.trackwheelClick(status, time);
}
}