04-26-2012 09:00 AM
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!
Solved! Go to Solution.
04-26-2012 09:16 AM
Have you tried Field.FIELD_HCENTER as a style?
04-26-2012 09:24 AM
Can you post your code , how you are trying to set the style.
Thanks
Rabi
04-26-2012 10:23 AM
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
04-26-2012 10:38 AM
"Numeric Choice field has not got any constructor which accepts style as a parameter."
You are right, never noticed that! Oh well
04-26-2012 01:31 PM
Since style can't be a parameter, does that mean you can't make it centered?
04-27-2012 02:20 AM - edited 04-27-2012 02:22 AM
Try this if found solution give me like and accept the solution
HorizontalFieldManager hfm5 = new HorizontalFieldManager(HorizontalFieldManager.USE_
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.FIE
nChoice.setMargin(0,0,0,100);
hfm5.add(nChoice);
add(hfm5);
04-27-2012 06:21 AM
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.