BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-29-2010, 08:06 PM   #1 (permalink)
New Member
 
Join Date: Oct 2010
Model: 9700
PIN: N/A
Carrier: DTAC
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Offline  
Old 11-30-2010, 08:40 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default Re: Customize ObjectChoiceField question

Please have a read through this sticky post at the top of the forum: How to paste 100% FORMATTED Source Code In Your Forum Posts

My poor old eyes get enough abuse looking at source code all day without having to try to remember the nesting structure.
__________________
My other Blackberry is a PlayBook.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: Customize ObjectChoiceField question
Thread Thread Starter Forum Replies Last Post
8310 GPS question Crockett General 8300 Series Discussion - Curve 11 01-25-2008 03:37 PM
Question about unlocked blackberry AmyKate General BlackBerry Discussion 3 12-22-2007 11:57 AM
Question about adding contact by email on BBM (blackberry messenger) nyubi General 8100 Series Discussion - Pearl 7 04-25-2007 11:40 PM
The question of Headset... nandoc Hardware & Accessories 17 04-14-2007 05:11 PM
BlackBerry Redirector / Mail Connector Question - Please Help! korpanopoly General BlackBerry Discussion 3 01-29-2007 06:58 PM





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.