ChoiceField

Hello, I had a few problems by performing a ChoiceField correctly.  I want to have a Choicefield with just two options in there.  What would be the right way to do this?

Thank you

Scientist

take an array of strings.

[] Str As String = {"First", "Second"}

Choicefield ObjectchoiceField = new ObjectchoiceField("",str);

Add (choiceField);

I hope this help you.

------------------------------------------------------------------------------------
Kudo press to say thank you to the developer.
Also, press accept it as a button when you got the Solution.

Tags: BlackBerry Developers

Similar Questions

  • How to recover data from the choicefield retained

    Hello

    How to recover data from the choicefield retained

    Thank you

    SujithRavindran

    getSelectedIndex method will help you.

  • what the? (ChoiceField) .getChoiceCached (int) online: 898 NullPointerException

    Why I get this error?   (ChoiceField) .getChoiceCached (int) online: 898 NullPointerException

    The ChoiceFeild object is not null.

    JDE 5.0, 1.6.latest, Windows XP pro 32-bit jdk 1.3.0 eclipse plugin

    The exception gives no message.

    Just found the bug, here's the code.

    Sort = new InData [X];       Suppose X 4 >
    Type [0] =...

    sort [1] =...

    Sort [2] =...

    Sort [3] =...

    That is the problem - the sorting matrix is defined over a length of X but is filled less of X items

    sortChoice = new TransparentObjectChoiceField ("", sort, 0, Field.FIELD_VCENTER, orig) {}
    {} public void paint (Graphics graphics)
    graphics.setColor (menuTextColor);
    Super.Paint (Graphics);
    }
    };

    It was hard to find because the exception was thrown only when the screen with the sortChoice object was pushed and then of course there were several of these objects on the screen so it is difficult to see who wants to go.

    Thank you.

  • How to add data to ChoiceField?

    honestly, I looked on the forum and I could not know how to do this very basic thing - add data (strings, in this case) to a choicefield.

    Try using ObjectChoiceField instead, so you can call setChoices or define the choices when building using:

    ObjectChoiceField(String label, Object[] choices)

    or

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

    http://www.BlackBerry.com/developers/docs/5.0.0api/NET/rim/device/API/UI/component/ObjectChoiceField...

  • ObjectChoiceField and ChoiceField$ ChangeOptionChoiceField classcastexception

    one line in fieldchangelistener of my ObjectChoiceField, I have this line:

    choice final int = (field) .getSelectedIndex ((ObjectChoiceField));

    but he gives this exception:

    ClassCastException: Cannot mount net.rim.device.api.ui.component.ChoiceField$ ChangeOptionChoiceField (id = 91958272) at net.rim.device.api.ui.component.ObjectChoiceField

    How can I me index newly selected of the ObjectChoiceField in the Interior of the listener?

    I tried to use a final ObjectChoiceField so I could access it just inside the listener, but it I still get the value of previous for the selected index.

    my code:

    final distance ObjectChoiceField = new ObjectChoiceField ("Menu choose:", menu list);

    If (menuList.length > 1) {}
    Dialog.Alert ("length =" + menuList.Length);
    Flash = Integer.ToString (menu list [Dialog.ask ("which menu?", menuList, 0 "")] .getValue ());
    Dialog.Alert ("Flash =" + Flash);
    distance.setChangeListener (new FieldChangeListener () {}
    ' Public Sub fieldChanged (field field, int context) {}
    choice final int = (field) .getSelectedIndex ((ObjectChoiceField));
    Dialog.Alert ("get next choice");
    final int choice = distance.getSelectedIndex ();
    Dialog.Alert ("location =" + choices);
    Field.Get
    final int ctx = context;
    New Thread() {}
    public void run() {}
    loadMenus (ctx, choice);
    }
    }. start();
    }
    });

    objectSymbol = new ObjectChoiceField ("", ARRAY, 0, Field.FIELD_LEFT)
    {
    protected void fieldChangeNotify (int context)
    {
    indexCurrency = getSelectedIndex();
    }
    };

  • 2 side by side choicefields?

    Is it possible to place 2 choicefields side by side on the screen OptionsProvider? I'm trying to display a time and I wish it were

    choicefield1: choicefield2

    Is this possible if?

    Yes. Put them in flofieldmanager.

    FlowFieldManager f = new FlowFieldManager();

    f.Add (Choice1);

    f.Add (Choice2);

    mainScreen. Add (f);

  • ChoiceField FieldChangeEvent

    I have a ChoiceField field and when a user selects a different choice, I want to get data from this choice. But when I scroll through the list of choices, the event is raised each time. I only get the data when the user selects a new choice. cField.toString () is the last selected value.

    For example:

    Select color: Red

    The options are red, blue, green, Orange.

    The code below will be called 3 times when I go from red to blue to green to Orange.

      private FieldChangeListener CreateFieldChangeListenerEventHandler() {
            FieldChangeListener changeListener = new FieldChangeListener() {
                /* (non-Javadoc)
                 * @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(net.rim.device.api.ui.Field, int)
                 */
                public void fieldChanged(Field field, int context) {
                    ChoiceField cField = (ChoiceField)field;
    //              Data is always called when traversing through the list of choices.
    //              getData(cField.toString());
                }
            };
    
            return changeListener;
        }
    

    What Miss me?

    OK I thought about it. I finished by using the context to see what setting that caused the event to be fired. Although it doesn't seem to be any documentation on what integer values correspond to the.

    private FieldChangeListener CreateFieldChangeListenerEventHandler() {
        FieldChangeListener changeListener = new FieldChangeListener() {
            /* (non-Javadoc)
             * @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(net.rim.device.api.ui.Field, int)
             */
            public void fieldChanged(Field field, int context) {
                if(context == 0)
                {
                    return;
                }
    
                ChoiceField cField = (ChoiceField)field;
                Dialog.alert(cField.getChoice(cField.getSelectedIndex()).toString());
            }
        };
    
        return changeListener;
    }
    
  • ChoiceField help

    Hi here is my problem

    I've created a subclass (DynamicObjectChoice) that extends ObjectChoiceField and created an another subclass (MyObjectChoiceListener) that extends FieldChangeListener.

    In DynamicObjectChoice I crushed constructor and take an int parameter.

    Then in my main class, I've created a DynamicObjectChoice and fill in a loop like this.

    for (int i = 0; i < someInt; i++) { choiceFieldArray[i] = new DynamicObjectChoiceField(Label, choices, 0, i);
                MyObjectChoiceListener listener= new MyObjectChoiceListener();
                choiceFieldArray[i].setChangeListener(listener);
                add(choiceFieldArray[i]);}
    

    and crushed fieldChange MyObjectChoiceListener with this method.

    public void fieldChanged(Field field, int context) {
                System.out.println((DynamicObjectChoiceField)field).getLabel());
    }
    

    AND HE SAID CLASSCASTEXCEPTION! Why? im stuck here.  I have founfd that I have change

    System.out.println((DynamicObjectChoiceField)field).getLabel());
    

    TO

    System.out.println((ChoiceField)field).getLabel());
    

    It works but I need other methods that are available only on DynamicObjectChoiceField. Help, please!

    I solved this problem, but I don't understand why I should use it. I think that the event 'clone' the field being passed at run time, and when you try to cast it giives you classcast exception. Solution was this:

    ((DynamicObjectChoiceField) field.getOriginal()).getLabel();
    

    So in the hope that it helps someone else.

  • Several choicefields

    I have several fields of choice in a screen and I want to know who a user waqs click on how to use ield changes

    ' Public Sub fieldChanged (field field, int context)
    {
    I need to know that one has been cahnged to perfotm options

    If ((contexte & ChoiceField.CONTEXT_CHANGE_OPTION)! = 0)
    {
              
    pushBBScreen();
    }
    }

    Please review the below extract of code, you can see how the setChangeListener is used for 'rgb' and 'RVB1 '.

            RadioButtonGroup rbg = new RadioButtonGroup();
            RadioButtonField rbf1 = new RadioButtonField("yes",rbg,false);
            RadioButtonField rbf2 = new RadioButtonField("No",rbg,false);
            add(rbf1);
            add(rbf2);
    
            rbg.setChangeListener(new FieldChangeListener ()
            {
                public void fieldChanged(Field field, int context)
                {
                    System.out.println("Field Changed in First");
                }
            });
    
            RadioButtonGroup rbg1 = new RadioButtonGroup();
            RadioButtonField rbf11 = new RadioButtonField("yes",rbg1,false);
            RadioButtonField rbf22 = new RadioButtonField("No",rbg1,false);
            add(rbf11);
            add(rbf22);
    
            rbg1.setChangeListener(new FieldChangeListener ()
            {
                public void fieldChanged(Field field, int context)
                {
                    System.out.println("Field Changed inside second");
                }
            });
    
  • ChoiceField Select event

    How are we going to another screen on the selection of the item in the Dropdownlist control.

    What is the interface which should I implement

    and what method should I use.

    In your case, it would of course getSelectedIndex CF field.

    Dim str As String = (String) cf.getChoice (cf.getSelectedIndex ());

    It should work.

  • ChoiceField default value does not match the visible value

    I'm creating an ObjectChoiceField and have noticed a strange behavior.

    As soon as the application loads I see that choice at index 0 is the selected choice. However, if I call mychoice.getSelectedIndex () returns 1. I even tried to call this.setSelectedIndex (0) in the constructor, but it remains 1. If anyone has experienced this?

    NVM. freakin ' getIndex/getSelectedIndex are too similar!

  • Combo box help

    HY everybody, I'm a beginner in the development of Bb, and I'm doing a drop-down list box. I wrote this code:

    ChoiceField ObjectChoiceField;
    choiceField = new ObjectChoiceField ("select your choice:", new String [] {"choice 1", "Option 2", "3", "Option 4"});
    Add (choiceField);

    but I want that when I select one choice, to open a new drop-down list with other choices. How can I do this?

    The simplest approach is to use a FieldChangeListener on the original choiceField.  In the associated fieldChanged(), check the value, and add the field appropriate.

    See Methode.setchangelistener (...) .

    Is not in fact trivial to do, there are a number of interesting concepts involved in this and if I had time, I could be able to hit a sample, I think it's a good exercise for you to try yourself.

    I would like to do the 'screen' the listener for the ObjectChoiceField since you use this to change the actual user interface.

    Then, you need to add the field.  You can simply add this.  But if they choose a different choice, you might want to remove this field and add another.  And you need to know where to put this field on the screen also.

    There are two approaches to this.

    Either put a dummy field in the right place (a NullField is a good choice) and replace it with what you want to add.  If you change your mind, replace what you added earlier with the new field.  Look at the Manager for more information replace() method.

    In addition, and my preferred solution, must always add a handler to the place that you want to update.  When chjoice changes delete everything in the Manager (deleteAll) and then add what you want.

    The final Curveball is the listener gets invoked frequently, as the user moves in the choice.  There are some complicated approaches to stop what is happening, who are probably not worth to be discussed right now.

    So, have a go, let us know how you go and good luck.

  • Align ButtonField Center in HorizontalFieldManger when ObjectChoceField is not selected

    Hello
    I have developed a screen in which there's a topic labelField below that there is an ObjectChoiceField... My position and ObjectChoiceField do not scroll and will remain constant, under the title and ChoiceField object I have some data that must be the subject of a scroll and I could achieve this scrolling thing but my problem is that I place a button below these materials and placed this button in HorizontalFieldManager as follows

    ButtonField back;
    HorizontalFieldManager But_Back = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER);
    Back = new CustomButtonField ("Back", ButtonField.FIELD_HCENTER);
    Back.setChangeListener (this);
    But_Back.Add (back);

    The first problem: At when only the header of the loading of the page and object coice field and my left side coded hard LabelField will be present and the button below and when I select the value in the ObjectChoiceField then the values corresponding to the labelField letside will be displayed all I can attchieve using the fieldChanged but my button that is currently I am unable to put in the Center... that when the page is loaded without values are present, so the button is to the left side and when I select a value of ObjectChoiceField, then it is aligned to the Center, I want to be at the Center...
    FYI: in the order of scroll implememtn in my Constructori say

    Super (new VerticalFieldManager (), NO_VERTICAL_SCROLL);
    Here I put the code for coice position and object fields in two different HorizontalFieldManager and then announces to the screen
                 
    For the scrolling now, I create a verticalFieldManger like:
    VerticalFieldManager vor = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL |) VerticalFieldManager.VERTICAL_SCROLLBAR);
    and each variable left and right in addition to HorozontalFieldmanger
    HFM HorizontalFieldManager = new HorizontalFieldManager();
    VFM. Add (HFM);

    and at the end I say
    HorizontalFieldManager But_Back = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER);
    Back = new CustomButtonField ("Back", ButtonField.FIELD_HCENTER);
    Back.setChangeListener (this);
    But_Back.Add (back);
    VFM. Add (But_Back);
    Add (VFM);

    Add Field.USE_ALL_WIDTH in your VerticalFieldManager and DrawStyle.HCENTER in your ButtonField.

    Something like:

    VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH | VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR);
    ///
    ///
    HorizontalFieldManager But_Back = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
    ButtonField  Back = new ButtonField("Back",DrawStyle.HCENTER);
    Back.setChangeListener(this);
    But_Back.add(Back);
    vfm.add(But_Back);
    add(vfm);
    

    Concerning

    Bika

  • Open objectChoiceField press ENTER, curve 8520 (JDE 5.0)

    Hello

    I added an objectChoiceField on horizontalfieldManager (hfm) and hfm is added to the main vericalfieldmanager.

    I click the trackpad, opens my objectChoiceField and I am able to make the selection,

    but when I press on enter (when ojectchoicefield is focused), the focus moves to the next field. I want to open choicefield when I press on enter the update choicefield.

    Thanks in advance.

    Thank you and best regards,

    Fekri

    I created this example... try what he's working on the press to enter the key

    SerializableAttribute public class HelloWorldScreen extends form {}

    ObjectChoiceField objectChoiceField;

    public HelloWorldScreen()
    {
    setTitle ("Screen Test");

    objectChoiceField = new ObjectChoiceField ("Test", new String [] {"1", "2", "3"});
    Add (objectChoiceField);

    }

    {} protected Boolean keyChar (char c, int status, int time)

    If (getFieldWithFocus () == objectChoiceField & c == Characters.ENTER) {}
    EventInjector.invokeEvent (new EventInjector.NavigationEvent (EventInjector.NavigationEvent.NAVIGATION_UNCLICK, 0, 0, status))

    ));
    }
    Returns true;
    }

    }

  • Repeated cannot find symbol errors

    Hi, I'm a newb at blackberry JDE and java in general. I'm used to working to loosen typed and extended as php environments. I'm creating a simple application tasking to teach myself State and management of the data and other. I've made very little progress and I am already stuck. I looked through the blackberry API tutorial resources and searching the forums, but have been unable to find answers (probably seen them and just he did not know that I am so lost). I met two roadblocks in the following code, which intervened in the section highlighted with #. The following class is called by a class of application and built and tested successfully, without the sharps.

    1.) whenever I try to add whatever it is inside the class ButtonListener (by adding the code in force, that is), as a string, call a method or try to push something to the front of the battery of the display, I get the error 'cannot find symbol' during compilation. I guess it's a problem with the legacy of some sort, but I am totally lost and frustrated.

    2.) once it's resolved, I want to insert a switch statement where the # is to add and remove items from different field of the display depending on the value selected in the ObjectChoiceField itemTypeField. I think, I need to set the index of the choicefield initially and then retrieve it later, but I don't know how.

    Any help will be greatly appreciated.

    import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.Manager.*;import net.rim.device.api.ui.UiApplication;
    
    /** *  */public class NewItemScreen extends MainScreen{    //Set Form Variables        private LabelField applicationTitle = new LabelField("New Item");        private EditField itemTitleField = new EditField("Title: ", "");        private String typechoices[] = {"Project", "Task", "Event"};        private ObjectChoiceField itemTypeField = new ObjectChoiceField("Type: ", typechoices, 0);
    
        public NewItemScreen()    {        super();        //Add to Screen        setTitle(applicationTitle);        add(itemTitleField);        add(itemTypeField);        //Set Listeners        itemTypeField.setChangeListener(new ButtonListener());       }
    
        //Implement Button Listener    private class ButtonListener implements FieldChangeListener    {        public void fieldChanged(Field field, int context)        {            if(context != FieldChangeListener.PROGRAMMATIC) // Perform action if user changed field.            {                if(field == itemTypeField)                {                    ####################                }            }        }    }}
    

    (1) can't find symbol error occurs when you create an instance of a class not created no where... Or the class path may not be configured correctly. Compiler isn't aware of the path where the classes... Also when we forget to import the required classes as well...

    if(context != FieldChangeListener.PROGRAMMATIC) // Perform action if user changed field.               {                    if(field == itemTypeField)                   {                            ####################                 }            }
    

    The first if the cheque is not necessary however... Also, I would say not to use the double equals "is" use as field.equals (itemTypeField)...

    (2) I did not understand, what exactly you need to...

    Thank you!

Maybe you are looking for