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.

inside custom component

Java Development

Reply
Highlighted
Trusted Contributor
Posts: 167
Registered: ‎06-30-2011
My Device: n/a
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!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: NumericChoiceField alignment in the GUI

Have you tried Field.FIELD_HCENTER as a style?

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: NumericChoiceField alignment in the GUI

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

 

Thanks

Rabi

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
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

 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

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

 

 

Trusted Contributor
Posts: 167
Registered: ‎06-30-2011
My Device: n/a
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?

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
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);

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
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.