Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
QuestionMan
Posts: 167
Registered: ‎06-30-2011
My Carrier: Koodo
Accepted Solution

NumericChoiceField alignment in the GUI

I can't seem to move my numericChoiceFields anywhere, even though all of my other fields will move where I want them to go. Does anybody know how I can do this? I'm simply trying to center them.

 

PS. I would much prefer to use NumericChoiceFields instead of ObjectChoiceField due to a large amount of numbers.

 

Thanks!

Please use plain text.
Developer
peter_strange
Posts: 17,638
Registered: ‎07-14-2008

Re: NumericChoiceField alignment in the GUI

Have you tried Field.FIELD_HCENTER as a style?

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Carrier: Vodafone

Re: NumericChoiceField alignment in the GUI

Can you post your code , how you are trying to set the style.

 

Thanks

Rabi

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Carrier: Vodafone

Re: NumericChoiceField alignment in the GUI

NumericChoiceField and  ObjectChoiceField both inherited from ChoiceField class ...

 

Object choice field has got a constructor where user can pass style as FIELD.HCENTER

ObjectChoiceField(String label, Object[] choices, int initialIndex, long style) 

but 

Numeric Choice field has not got any constructor which accepts style as a parameter.

 

Regards

Rabi Ray

 

 

 

Please use plain text.
Developer
peter_strange
Posts: 17,638
Registered: ‎07-14-2008

Re: NumericChoiceField alignment in the GUI

"Numeric Choice field has not got any constructor which accepts style as a parameter."

 

You are right, never noticed that!  Oh well

 

 

Please use plain text.
Trusted Contributor
QuestionMan
Posts: 167
Registered: ‎06-30-2011
My Carrier: Koodo

Re: NumericChoiceField alignment in the GUI

Since style can't be a parameter, does that mean you can't make it centered?

Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 131
Registered: ‎04-19-2012
My Carrier: Nokia

Re: NumericChoiceField alignment in the GUI

[ Edited ]

Try this if found solution give me like and accept the solution

 

HorizontalFieldManager hfm5 = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);

 

hfm5.setMargin(10,0,0,10);

 

hfm5.add(new LabelField("Class "));

 

String Class[]={"Select","9","10","11","12","UG","PG"};

 

nChoice=new ObjectChoiceField("",Class,0,ObjectChoiceField.FIELD_LEFT);

 

nChoice.setMargin(0,0,0,100);

 

hfm5.add(nChoice);

 

add(hfm5);

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Carrier: Vodafone

Re: NumericChoiceField alignment in the GUI

Hi

 

Try this code ...i have extended the Object choice field to behave like a Numeric field and with the style option

 

package mypackage;

import net.rim.device.api.ui.component.ObjectChoiceField;

public class CustomObjectChoiceField extends ObjectChoiceField {

public CustomObjectChoiceField(String label, int i, int j, int initialIndex, long style) {
super(label , new Object[]{""}, initialIndex,style);
int initialValue = i;
int objSize = j+1-i;
Object[] tmpChoice = new Object[objSize];

for (int k = 0; k <objSize; k++) {
tmpChoice[k] = Integer.toString(initialValue);
initialValue= initialValue+1;
}
this.setChoices(tmpChoice);
}
}

 

 

Call to be made like  :

CustomObjectChoiceField chcFld = new CustomObjectChoiceField("Test", 0, 10, 0, Field.FIELD_HCENTER);
CustomObjectChoiceField chcFld1 = new CustomObjectChoiceField("Test", 5, 100, 0, Field.FIELD_HCENTER);

 

 

Hope this helps.

Please use plain text.