Customize ObjectChoiceField question
Please Login to Remove!
I have done with ObjectChoiceField customization and it works fine. But when I press myobjectchoiceField, it will show "the content list" hover on it. It's not looked quite good because myobjectField was set on the left of the screen. So I want to move "the content list"(not a drop down) to the center of the screen. Can anybody tell me how to do this ?
Here this is a code :
(credit by perumal_n)
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.component.ObjectChoiceField;
import java.lang.String;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.Font;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
//import org.utility.DSConstants;
public class CustomChoiceField extends ObjectChoiceField {
private int _bgWidth = 110;
private int _bgHeight = 30;
private boolean _hasFocus = false;
String[] m_Choices;
private int m_ChoiceFieldWidth;
private int m_TextMarginRight = 5;
private int m_TextMarginLeft = 5;
private Bitmap DopDownImgOn, DopDownImgOff;
private Font FONT_PLAIN;
private String visibleText;
private int m_MarginTop;
public CustomChoiceField(String label, String[] choices, int initialIndex) {
super(label, choices, initialIndex,CustomLongChoiceField.FIELD_RIGHT);
m_Choices = choices;
DopDownImgOff = Bitmap.getBitmapResource("dropdown_s.png");
DopDownImgOn = Bitmap.getBitmapResource("dropdown_off_s.png");
FONT_PLAIN = Font.getDefault().derive(Font.PLAIN, 5, Ui.UNITS_pt);
Font currFont = Font.getDefault().derive(Font.PLAIN, 3, Ui.UNITS_pt);
for (int i = 1; i < choices.length; i++) {
if (m_ChoiceFieldWidth < currFont.getAdvance(choices[i]))
m_ChoiceFieldWidth = currFont.getAdvance(choices[i]);
}
m_ChoiceFieldWidth += m_TextMarginLeft + m_TextMarginRight;
}
public int getPreferredHeight() {
return _bgHeight;
}
public int getPreferredWidth() {
return _bgWidth;
}
protected void layout(int width, int height) {
if (m_ChoiceFieldWidth == 0) {
m_ChoiceFieldWidth = width;
_bgHeight = height;
}
super.layout(width, height);
setExtent(_bgWidth, _bgHeight);
}
protected void onFocus(int direction) {
_hasFocus = true;
// super.onFocus(direction);
invalidate();
}
public void setBusiness(String[] choices) {
this.m_Choices = choices;
invalidate();
}
protected void onUnfocus() {
_hasFocus = false;
// super.onUnfocus();
invalidate();
}
protected void paint(Graphics g)
{
// DopDownImg = Bitmap.getBitmapResource("scroll.PNG");
if (DopDownImgOn instanceof Bitmap) {
m_MarginTop = (DopDownImgOn.getHeight() - FONT_PLAIN.getHeight()) / 4;
visibleText = (getSelectedIndex() == -1 || getSelectedIndex() >= m_Choices.length) ? ""
: m_Choices[getSelectedIndex()];
if (_hasFocus == false) {
g.drawBitmap(0, 0, DopDownImgOff.getWidth(), DopDownImgOff
.getHeight(), DopDownImgOff, 0, 0);
} else {
g.drawBitmap(0, 0, DopDownImgOn.getWidth(), DopDownImgOn
.getHeight(), DopDownImgOn, 0, 0);
}
g.drawText(visibleText, m_TextMarginRight, m_MarginTop,
DrawStyle.ELLIPSIS, DopDownImgOn.getWidth() - 30);
g.setFont(FONT_PLAIN);
// g.pushContext(clip, xOffset, yOffset);
// g.popContext();
}
invalidate();
}
}
I tried to use CustomLongChoiceField.FIELD_HCENTER and myObjectChoiceField(a drop down) was changed to field in right to center.Thats not what I want to do.
Please help
Thanks ,
Regards
|