BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 11-29-2010, 09:06 PM   #1
jutikorn
New Member
 
Join Date: Oct 2010
Model: 9700
PIN: N/A
Carrier: DTAC
Posts: 4
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, 09:40 AM   #2
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Customize ObjectChoiceField question

Please have a read through this sticky post at the top of the forum: http://www.blackberryforums.com/deve...rum-posts.html

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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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 04:37 PM
Question about unlocked blackberry AmyKate General BlackBerry Discussion 3 12-22-2007 12:57 PM
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 07:58 PM


6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF picture

6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF

$155.59



CBB61 250V  Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF picture

CBB61 250V Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF

$129.95



45/5 MFD ±5% Dual Run Capacitor 370 450 VAC CBB65 AC Motor HVAC 45+5 uF Fan 10pk picture

45/5 MFD ±5% Dual Run Capacitor 370 450 VAC CBB65 AC Motor HVAC 45+5 uF Fan 10pk

$89.99



5pc Radial Electrolytic Capacitor 250V 100V 50V 25V 16V 0.22uF-4700uF 10000uF picture

5pc Radial Electrolytic Capacitor 250V 100V 50V 25V 16V 0.22uF-4700uF 10000uF

$27.99



5 MFD AC Capacitor, 5uF ±5% 370VAC/440 Volt Oval Run Start Capacitor  picture

5 MFD AC Capacitor, 5uF ±5% 370VAC/440 Volt Oval Run Start Capacitor 

$9.97



1/5pcs 100V~400V 0.1uF~100uF MKP Audio Metallized Polypropylene Film Capacitor picture

1/5pcs 100V~400V 0.1uF~100uF MKP Audio Metallized Polypropylene Film Capacitor

$63.90







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