ObjectChoiceField

Hello

I have used described as follows:

class Employee
{
int _Eid;
int _Ename;
public Employee(){}
}

Now let's say I want to create a list of employees with the ID and fill in a drop down list of 'ObjectChoiceField '... What is the best way to do it?

When the user selects "Rob" in the menu dropdown, I should be able to determine "_Eid" of Rob.

Can I do this?

If the list will change, then a BigVector is a good idea.

But you don't have to extract them in a table because the ObjectChoiceField requires a range of choices, not a BigVector of choice.

What I usually do in this situation sot is initially put the data in a vector during the processing of the download, and then copy the vector in a table as soon as we roughly fixed list.

People say things are dynamic, but they do not change every second, you have to do something, like stuff from the user interface of the process and thus convert the vector table collection (or BigVector) and back is not a big problem.  See also Arrays class - there are a lot of utilities such as the binary search and sort who also help.

The Compariator is actually nothing to be frigthened of.  In your case, you will create a new class that extends the object and implements the required method.  You can actually have a number of different compariators.  Here's a quick example to help you get started.

class EmployeeComparator implements comparator
{

public int compare (Object o1, Object o2) {}

If (instanceof employee o1 & o2 instanceof employee) {}

Employee e1 = o1 (employee);

Employee e2 = o2 (employee);

int compareValue = ei._Ename.compareTo (e2._Ename);

If (compareValue == 0) {}

name is the same, the id?

compareValue = e1._Eid - e2._Eid;

}

CompareValue return;

}

return 0; No employees!

}

}

Tags: BlackBerry Developers

Similar Questions

  • ObjectChoiceField.getContextMenu () .getDefaultItem () .run () not working OS 5.0

    Hello
    I have an application that works well with the OS 4.6.247, but with the 5.0 OS, I have a problem with the function ObjectChoiceField.getContextMenu () .getDefaultItem () .run ().

    Is to throw NullPointerException.

    The code is the same on OS4.6 and OS 5.0

    Any idea?

    Thank you

    Everything is OK with:

    SerializableAttribute public class MyObjectChoiceField extends ObjectChoiceField {}
    Private boolean _IsFocusable;
    public MyObjectChoiceField() {}
    Super();
    }
    public MyObjectChoiceField (String Label, Object [], int InitialIndex, long Style) {}
    Super (label, Choices, InitialIndex, style);
    }
    public boolean isFocusable() {}
    Return _IsFocusable;
    }
    public void SetFocusable (boolean Focusable) {}
    _IsFocusable = active;
    }
    public void ShowContextMenu() {}
    invokeAction (Field.ACTION_INVOKE);
    }
    }

  • 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;
    }

    }

  • Test the State of ObjectChoiceField

    Hi all. I'm working on my first app, and I'm trying to learn how to dynamically change the fields on the screen according to the current state of an ObjectChoiceField. I have the setup of ObjectChoiceField with a listener that works properly. I'm stuck on how to detect what value in the ObjectChoiceField is currently selected. Pretty much, I am able to detect that the field has been modified, but not that. Below I've linked the code with # signs showing where I'm going to the place of the logic to decide which field returned to push on the screen.

    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.equals(itemTypeField))
                    {
                        #################
                    }
                }
            }
        }
    }
    

    As a suggestion, you can replace #... # with something like

    int index = itemTypeField.getSelectedIndex ();

    String selectedOption = typechoices [index];

    If {(selectedOption.equals ('Project'))

    Does that help?

  • How to stop the ObjectChoiceField prompt you to save the window?

    Hi, I have 3 ObjectChoiceFields in my code to let the user select the information, then it passes the value to the next screen again. However when I click on the back button to return to the previous screen and exit the application, he always invites a window of notice asking me if I want to save, delete, or cancel. If I click on save, and then run the code again, the ObjectChoiceFields still shows the original value, if the backup does not really work. I would like to know how to do the backup works, so that the next time I run the code, it will present the values I chose last time. or another solution, how can I stop ObjectChoiceField prompt you to save the window?

    Thank you very much!

    Hello

    There are two ways to do this (assuming that the judgment save prompt will solve the problem)

    1.

    In the api using onSavePromptMethod();

    This method is a member of the screen class (AFAIK). You can override this and simply return true;

    Who can't let the application display quick check

    2.

    First, use this code in the onClose method

    If (getMainManager () .isDirty ()) {}
    getMainManager () .setDirty (false);
    }

    I found that 2 still works and uncertain about 1. But I prefer to use 1 and you asking to try that and tell if it worked on the side or not...

  • Weird ObjectChoiceField in OptionsProvider

    I don't really know if it is related to the OptionsProvider, but here is the screen with the problem (labels wrapped):

    I have several ObjectChoiceField- s, added to the screen, and when I open it first time in the application I see that.

    The next time or when I opened this page of third... everything looks OK.

    It is interesting when it happens in 7.0 + and is not in 6.0

    All the fields have been created as:

    new ObjectChoiceField("Homesceen Icon" , new String[] { "On", "Off" } , 0);new ObjectChoiceField("Update Frequency" , new String[] { "30 minutes", " 15 minutes ",  "10 minutes"  } , 0);
    

    OK, if someone is interested, to fix it i:

    1 created horizontal custom Manager,

    2 put LabelField and ObjectChoiceFiled with empty label

    3. in sublayout method defined calculated positions and extensions of these objects.

    It works as it should now.

    I guess that, OS 7.0 introduced a bug in ObjectChoiceField.

  • Setting width of objectchoicefield

    Hello

    I want to ObjectChoiceField without tag and set its width on screen width in my project. Suggest me the way to do this

    Thanks in advance

    Check this box to learn how to make a custom presentation:
    http://supportforums.BlackBerry.com/T5/Java-development/how-to-extend-Manager/Ta-p/446749

    in your case, you can also try to crush getPreferredWidth, but do not know if it works on a choicefield

  • Dynamically fill ObjectChoiceField according to the selected box

    Hi all

    I have a few boxes on my screen and an ObjectChoiceField. I have to fill this ObjectChoiceField dynamically according to the selected checkbox.  I have a few separate hard-coded (I announced on the same screen) array of strings for all the boxes.

    If I select the first box, then ObjectChoiceField must be populated with the corresponding array of strings... and so on...

    Thank you and best regards.

    You just need to use

    .setChoices ();

  • Objectchoicefield custom

    Hai all,
    I need to implement the button and label field of objectchoice with separate click to button and label (or listview complete) event, please give suggestions to implement the custom objectchoicefield.

    The name of the company must establish a click event to view the details and the distinct x (delete button) need separate, click event to remove the choice of listfield.

    Thank you.

    You ask a lot of us aren't you?

    I suggest you just start trying to do just one of these things, something code that you think the work and we could help you get the code works.

    But I must point out that I've never seen anything like that on the BlackBerry that works as an ObjectChoiceField and is the kind of thing you're after.  So I suspect that you maybe isn't able to implement features as requested, or if you can, it will take a lot of time.  You might think to simplify the obligation.

    Remember that an ObjectChoiceField is not a click event different for different parts of the drop down, so you won't be able to use it.  You need to create something else.  In this kind of situation, I have in the past, created a popup screen to display the values of 'pull down', but this clearly does not resemble a pull down, even if it provides the same functionality.

  • Transparent background for ObjectChoiceField

    I put an ObjectChoiceField on a screen that haves a background image. The image is painted in the overridden method of a VerticalFieldManager object. By default, the field itself is painted with a white background, but I want to display only the text and see the image below. The tag is painted with transparent bg, but the area of selection has a blue bg when concentrated and a white fuzzy when (it's what I want to change from transparent).
    Is there a way to do this without making plenty of low level painting?
    I tried this:

    ObjectChoiceField ocf = new ObjectChoiceField(tag, options, options.length - 1, Field.FIELD_BOTTOM | Field.FIELD_LEFT) {   public void paint(Graphics g) {       g.setBackgroundColor(0xFFFFFFFF); //the alpha byte is set to full transparent                     super.paint(g);   }};
    

    but has no effect.

    I would also like to paint the tag in a different color from that of the area of selection, and if possible, change background gray from the list of options in a semi-transparent.

    The ObjectChoiceField exposes no methods to control the color of background of the options bar.  The area behind the label should appear transparent, but the part of the option in the field should use the colors from the current theme.

  • DateField, HorizontalFieldManager + ObjectChoiceField = error

    I am creating a page layout so that there a datefield and objectchoicefield in the horizontalfieldmanger even, and it throws me illegalarguementexception every time. Can someone help me? Here is the code example.

    HFM HorizontalFieldManager = new HorizontalFieldManager();
    HFM. Add (new DateField ("Some Text:", Date () .getTime (new),))
    DateFormat.getInstance (DateFormat.TIME_DEFAULT)));

    HFM. Add (new ObjectChoiceField ("", new String [] {"some", "text"}));
    Add (HFM);

    The problem here is that the DateField occupies the entire width.  The ObjectChoiceField then try to deal itself.  He seems to be referring to the treatment of layout of a RichTextField and pass the width that it must work, and the string to be converted (in this case, it is "a little").  RichTextField barfs with an Exception, because there is no way that 'some' can fit in the space provided (-1 pixel).

    To get this working, you have to find a way to limit bandwidth claiming the DateField.  I thought you'd be able to do by indicating the field to put his time left (style == DateField.FIELD_LEFT, but which did not work, so I went back to my usual substitutions and created what follows, that works.)

    You can take it from here?

    HFM HorizontalFieldManager = new HorizontalFieldManager();
    HFM. Add (new DateField ("Some Text:", System.currentTimeMillis (),))
    {DateFormat.getInstance (DateFormat.TIME_DEFAULT))}
    public int getPreferredWidth() {}
    Return to 150;
    }
    Protected Sub layout (int width, int height) {}
    Super.Layout (getPreferredWidth (), height);
    }
    });
    HFM. Add (new ObjectChoiceField ("", new String [] {"some", "text"}));
    Add (HFM);

  • Characters.Escape and ObjectChoiceField

    Hi all

    I made an app that has an ObjectChoiceField and when you select an index, she throws you to another screen filtering what you see according to the selected index.

    When you are in the new screen and the user, press the ESC key to go back, the ObjectChoiceField displays the index that the user has selected before, and I want the ObjectChoiceField to set the default index value, is it possible?

    Not convinced this Sad_Bird idea is very "as object".  I don't think you want 2 screen to worry about screen 1.

    A number of options come to mind, the manifesto being once you got the selected index and screen 2, then in Screen1, just created all the index selected in your ObjectChoiceField to 0.  You can do so after you press display 2.

  • ObjectChoiceField FieldChangeListener problem

    Hi all

    I'm coding an application for 4.5 but testing on BB 9500.

    I want to a few call webservice on the choice of an ObjectChoiceField.

    But the problem is that the FieldChangeListener of the ObjectChoiceField fires on the development as well as on the selection of the field.

    How to distinguish two event?

    Thaks for your help in advance.

    Hi all

    I found the solution to my problem.

    Below is sample code for the solution.

    ObjectChoiceField myObjectField= new ObjectChoiceField("",new String[] { "" }, 0, FIELD_LEFT)
    {
        protected void fieldChangeNotify(int context)
        {
        new myObjectField_change_method();
        }
        public void focusChangeNotify(int arg0)
        {
        super.focusChangeNotify(arg0);
        }
    };
    

    In the code above myObjectField_change_method() is a method to be triggered when the field is selected.

  • Put two ObjectChoiceField side by side

    Hello

    I tried to put both components in a HorizontalFieldManager ObjectChoiceField, but I can't view both on the same line, it seems that the other is pushed off the screen to the right.

    I tried with Manager.NO_HORIZONTAL_SCROLL nothing works.

    Can anyone please help me;

    Thank you very much

    You can limit the width of one of them. These two talk on this subject, but for the different types of fields:

    http://supportforums.BlackBerry.com/T5/Java-development/can-t-put-BasicEditField-and-button-side-by-...

    http://supportforums.BlackBerry.com/T5/Java-development/please-help-with-trying-to-put-a-BasicEditFi...

    But if you are sure that they will hold next, you can set one on the left with the style

    Field.FIELD_LEFT and I think he'll try to stay as close to the left as it can.  Give it a try.

  • 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();
    }
    };

Maybe you are looking for