GetIndex

I create a table which displays a horizontal list of personal information added in wise.

Here I use the labelfield for the default display of information.but labelfield doesnot have getSelecetedIndex() method...

I have therefore implement this method in own... And my question is how to get inex position when I select one

particular table field... Is it all possible... I implement my coding like this... it's this way is right?...

I have also the array of objects affectante m to store each table oject... is possible to get the index of the position by getting the Explorer...

private String [] s1;

public Object [] table_position;

Public table (String []) s
{

S1 = s;

for (i = 0; i<>
{
label_name [i] = new Labelfield (s1 [i]);
HFM. Add (label_name [i]);
VFM. Add (HFM);
table_position [i] = hfm;

}
Add (VFM);

Hello

Public table (String []) s
{

S1 = s;

for (i = 0; i<>
{
label_name [i] = new Labelfield (s1 [i])

{

protected boolean navigationClick (int status, int time)
{
Boolean returnValue = false;
If (this.) GetIndex() == 0)
{

returnValue = true;

}

If (this.) GetIndex() == 1)
{

returnValue = true;

}

}

};

HFM. Add (label_name [i]);
VFM. Add (HFM);
table_position [i] = hfm;

}
Add (VFM);

Similarly, you can override the methods of the Manager of HorizontalFiled; and the method, you can get the domain using the

int i = this.getFieldWithFocusIndex (); You can even use other methods such as getLeafField() etc...

Tags: BlackBerry Developers

Similar Questions

  • Change the focus to the next field in the screen!

    Hi, I have a problem change the focus in the fields, suppose I have a list at least 200 records field and I need to change the focus in the field below (accept button)... remains the path to achieve this? in denavigationde?

    Screen

    -Manager

    -Manager

    TextField - button

    ListView-

    -Manager

    -Button (Accept)

    My screen can be so, but not necessarily be so.

    Thank you, in advance.

    It is relatively easy to divert attention if you know where it's going.  You can just do 'setFocus '.

    It is also relatively easy move focus generically.  For example, in a field, you can do things like

    Manager m = this.getManager ();

    int myIndex = this.getIndex ();

    int managerFieldCount = m.getFieldCOunt ();

    Field nextFocus = null;

    for (int i = myIndex + 1; i)< managerfieldcount="" ;="" i++="" )="">

    Field testField = m.getField (i);

    If {(testField.isFocusable ())}

    nextFocus = testField;

    break;

    }

    }

    If (nextFocus! = null) {}

    nextFocus.stFocus ();

    } else {}

    You can browse to the Manager and get the next field in the Manager of your Manager.

    Hope that gives you some ideas.

  • How to ignore, click on the button after the application of navigationClick()

    My application has 3 buttons to click on it as menu and me put FieldChangeListener to each of them.

    It works perfectly! but when I put my listField implemented with

      public boolean navigationClick(int status, int time) {
          Field focus = view.getLeafFieldWithFocus();
          Dialog.alert("Focus String :: " + focus.getIndex());
    
          if (focus instanceof ListField) {
          ListField listField=(ListField)focus;
    
          Dialog.alert("Selected Index"+listField.getSelectedIndex());
          Dialog.alert("Selected List Value"+listField.getCallback().get(listField, listField.getSelectedIndex()).toString());
    
          }else{}
          return true;
    
          }
    

    The listener on the buttons are override with navigationclick and ignore fieldlistenser.

    How can I solve this problem?

    Thank you

    When you're clicking on button getLeafFieldWithFocus(); Returns the instance ListField or ButtonField.

  • Newbie question - NullPointerException in enterEventDispatcher

    Hello

    I'm new to the Blackberry development and use the 4.6 SDK Eclipse plugin. I used the sample applications as a basis and try to add 3 buttons to my main screen. It's code to the constructor of the main screen

    public MyAppScreen() {        super(DEFAULT_MENU | DEFAULT_CLOSE);        try{            setTitle(new LabelField("My First App", LabelField.ELLIPSIS                 | LabelField.USE_ALL_WIDTH));                       FieldChangeListener listener = new FieldChangeListener() {              public void fieldChanged(Field field, int context) {                    Field buttonField = (Field) field;                  System.out.println("Button pressed: " + buttonField.getIndex());                }           };              HorizontalFieldManager hfm = new HorizontalFieldManager(                    Manager.HORIZONTAL_SCROLL);             ImageButton commBtn = new ImageButton(Field.FOCUSABLE,                  "img/comm_over.png", "img/comm.png");           commBtn.setChangeListener(listener);                        ImageButton accBtn = new ImageButton(Field.FOCUSABLE,                   "img/acts_over.png", "img/acts.png");           accBtn.setChangeListener(listener);                     ImageButton oppBtn = new ImageButton(Field.FOCUSABLE,                   "img/opp_over.png", "img/opp.png");         oppBtn.setChangeListener(listener);             hfm.add(commBtn);           hfm.add(new RichTextField(Field.NON_FOCUSABLE));            hfm.add(accBtn);            hfm.add(new RichTextField(Field.NON_FOCUSABLE));            hfm.add(oppBtn);                add(hfm);       }       catch(Exception e){         e.printStackTrace();        }   }
    

    I call it in my UiApplication class as follows

    public MyApp() {    MyAppScreen homePage = new MyAppScreen();    pushScreen(homePage);}public static void main(String[] args) {   MyApp app = new MyApp();    app.enterEventDispatcher();}
    

    ImageButton is a custom class whose code I made custom buttons sample application subject to change. When I run the application, I get a NullPointerException and stacktrace illustrates the exception in the MyAppScreen paint method.

    Is someone can you please tell me what could be wrong with the application.

    Thank you.

    @mantaker, sorry, it was just a typo. Fix the code.

    Thanks for all the answers. I solved the problem. Had missed on initialization in a constructor.

    I feel really stupid

  • Question of width for HorizontalFieldManager nin BB OS 6.0 and 7.0

    Hi all

    I developed a new application for BB OS 5.0, 6.0 and 7.0, which in its homepage has a bar containing different categories of navigation. The navigation bar is designed as:

    public HeaderMenu (String [] categories, HeaderMenuListener listCallback) {}
    Super(NO_HORIZONTAL_SCROLL |) NO_HORIZONTAL_SCROLLBAR | FOCUSABLE);
            
    mCategories = categories;
    mNewsListCallback = listCallback;
    mButtons = new CustomButton [mCategories.length];
    noOfCategories = mCategories.length;
    ND = this;
            
    mCategoryNavigator = new HorizontalFieldManager(FOCUSABLE |) HORIZONTAL_SCROLL |       HORIZONTAL_SCROLLBAR) {}

    public int getPreferredWidth() {}
    If (noOfCategories > 1) {}
    navigatorWidth = Display.getWidth () - mLeftNavigator.getWidth () - mRightNavigator.getWidth ();
    return Display.getWidth () - mLeftNavigator.getWidth () - mRightNavigator.getWidth ();
    }
    else {}
    Return Display.getWidth ();
    }
    };
                
    protected void sublayout (int maxWidth, maxHeight int) {}
    Super.sublayout (maxWidth, maxHeight);
    setExtent (getPreferredWidth (), getPreferredHeight());
    };
                
    };
    loadCategoryView();

    mLeftNavigator = new BitmapField (AppResolutionVariables.mLeftNavigationBtn, NON_FOCUSABLE);
    mRightNavigator = new BitmapField (AppResolutionVariables.mRightNavigationBtn, NON_FOCUSABLE);

    If (noOfCategories > 1)
    {
    Add (mLeftNavigator);
    }
    Add (mCategoryNavigator);
    If (noOfCategories > 1)
    {
    Add (mRightNavigator);
    }
    this.setBackground (BackgroundFactory.createSolidBackground (COLOR_MAROON));
    }
        
    /**
    The method of loading of new categories in a scroll handler.
    */
    private void loadCategoryView() {}
            
    int size = mCategories.length;
            
    Added table of buttons representative of the new categories to the Manager of scrolling.
    for (int i = 0; i)<>
    String categoryName = mCategories [i];
    mButtons [i] = new CustomButton (categoryName, DATA_FONT_BOLD, DATA_FONT_PLAIN,
    COLOR_MAROON, COLOR_WHITE) {}
                    
    public int getPreferredHeight() {}
    Return AppResolutionVariables.mLeftNavigationBtn.getHeight ();
    };
                    
    protected boolean navigationClick (int status, int time) {}
    int index = Arrays.getIndex (mButtons, this);
    If (index > = 0) {}
    mNewsListCallback.notifyHeaderButtonClick (index);
    }
    Returns true;
    }
    };
    mCategoryNavigator.add (mButtons [i]);
    }
    }

    Method takes care of asking left and right navigation buttons and scrollable Manager in the correct position.
    protected void sublayout (int maxWidth, maxHeight int) {}
            
    Super.sublayout (maxWidth, maxHeight);
    setExtent (getPreferredWidth (), getPreferredHeight());
            
    If (noOfCategories > 1) {}
    layoutChild (mLeftNavigator, maxWidth, maxHeight);
    setPositionChild (mLeftNavigator, 0, 0);
    }
            
    layoutChild (mCategoryNavigator, maxWidth, maxHeight);
    If (noOfCategories > 1) {}
    setPositionChild (mCategoryNavigator, mLeftNavigator.getWidth (), 0);
    } else {}
    setPositionChild (mCategoryNavigator, 15, 0);
    }
            
    If (noOfCategories > 1) {}
    layoutChild (mRightNavigator, maxWidth, maxHeight);
    setPositionChild (mRightNavigator, getPreferredWidth() - mRightNavigator.getWidth (), 0);
    }
    }

    The question do face is, when I scroll horizontally to the last button at the side bar, the last button is not visible completely, it becomes hidden by the right navigation button on the far right of HFM. This issue is in OS 6.0 and 7.0, but not in OS 5.0.

    Earlier, I had the problem in OS 5.0 so to fix it, I prevail on HFM getPreferredWidth() scrolling above, to return the width (width width HFM - width of navigation left button - not with the right navigation button scrolling) and it works fine. Can someone please fix the problem. Thanks in advance.

    Sorry just looking quickly here.

    The question which I believe is in your sublayout.  You tell your mCategoryNavigator field is the maximum width.  This isn't.  There only the width rest once the buttons have been added.

    There are two ways you can solve the problem.

    The simple way is just to spend the maximum width in the super.sublayout for mCategoryNavigator and no maxWidth.

    But the best way is to remove this sublayout completely and in your sublayout for the Manager.  In this handler, the layout and position your two buttons, then give the drop-down field which remains as its maximum width.

    Two other comments:

    (a) I would like to forget calling super.layout in your HeaderMenu and make everything in your own sublayout.  It would be a good exercise.  Remember the last thing you do is a setExtent, once you have placed all and so that you know how much space you need.

    (b) If you never call super.layout and then do a setExtent to get the correct size, the alarm should sound.  It's a bit like someone who gives a piece of paper, asking them to draw a picture and then decide that in fact the piece of paper is a different size of paper, that they needed to make the drawing.  You are actually asking someone else to do something and then ignoring what they have done (or at least a part of it).  If you find that you need to do, then look for another way as setExtent substitution causes the sorts of problems you found.

  • Problem with setChangeListener a button

    Hi all

    I have a problem on how to create table button listnerfor take these buttons appoint an xml file
    There are a few lines of my code please I need help

    for (temp = 0; temp)< nlist.getlength();="" temp++)="">
           
    HFM HorizontalFieldManager = new HorizontalFieldManager();

    NB = nList.getLength ();
    sendButton = new ButtonField [nList.getLength ()];
           
    Node nNode = nList.item (temp);
    If (nNode.getNodeType () == Node.ELEMENT_NODE) {}
     
    Element eElement = (element) nNode;
              
              
            
              
              
    sendButton [temp] = new ButtonField (getTagValue ("firstname", eElement), Field.FIELD_RIGHT) {}
    protected boolean navigationClick (int status, int time) {}
    fieldChangeNotify (0);
                  
    Returns true;
    }

    protected boolean keyChar (character char, int status,
    {int times)
    If (character == Keypad.KEY_ENTER) {}
    fieldChangeNotify (0);
    Returns true;
    }
    Return super.keyChar (character, status, time);
    }
    };
    Status.Show ("num" + Temp);
             
    I have = temp;
    FieldChangeListener listener = new FieldChangeListener() {}
    ' Public Sub fieldChanged (field field, int context) {}
    context = field.getIndex ();

    Status.Show ("label" + context);

    }
    };
    sendButton [i] .setChangeListener (listener);
                
             
              
              
    HFM. Add (sendButton [temp]);

    mainVerticalManager.add (hfm);

    ......

    I like the approach of akadyz.

    This is a reworked code which could be useful you have to understand my best suggestion:

    ButtonField [] sendButton = new ButtonField [nList.getLength ()];
    FieldChangeListener listener = new FieldChangeListener() {}

    ' Public Sub fieldChanged (field field, int context) {}
    If (instanceof ButtonField field) {}
    int matchedIndex = - 1;
    for (int i = 0; i)< sendbutton.length;="" i++="" )="">
    If (field, sendButton [i])) {}
    matchedIndex = i;
    break;
    }
    }
    }
    }
    };

    for (temp = 0; temp)< nlist.getlength();="" temp++)="">
          
    HFM HorizontalFieldManager = new HorizontalFieldManager();

    NB = nList.getLength ();
          
    Node nNode = nList.item (temp);
    If (nNode.getNodeType () == Node.ELEMENT_NODE) {}
     
    Element eElement = (element) nNode;
             
             
           
             
             
    sendButton [temp] = new ButtonField (getTagValue ("firstname", eElement), Field.FIELD_RIGHT) {}
    protected boolean navigationClick (int status, int time) {}
    fieldChangeNotify (0);
                 
    Returns true;
    }

    protected boolean keyChar (character char, int status,
    {int times)
    If (character == Keypad.KEY_ENTER) {}
    fieldChangeNotify (0);
    Returns true;
    }
    Return super.keyChar (character, status, time);
    }
    };

    sendButton [temp] .setChangeListener (listener);

    HFM. Add (sendButton [temp]);

    }

    mainVerticalManager.add (hfm);
    }

  • ListField - how to get the selected items

    Hi @all,

    I am running OS5 on a BB bold 9700 and development via eclipse.

    I tried to do a listfield and put it in a display of network manager, which works very well.

    As peter_strange did in a reply to a thread listfield, I tried to catch the click button on navigation through "makemenu.

    It works fine, but after processing the code according to the listfield (getindex), it shows a standard menu, which I don't want. I want just to get the index or the name of the current or selected fields and continue with the transformation by showing a new screen for example.

    In some other threads that I found excerpts concerning 'navigationclick', but I don't understand, what I have to do here and why. Th KB, I searched but I did find something to go further.

    Someone there who can help me with a small example?

    Thank you much in advance.

    CUA

    Michael

    You can create your own class or override her anonymously.

    new ListField (...) {replace the code of the method here}

    (blackberry is perhaps not the best way to start learning java...)

  • Retrieve the value of the dialog box

    Hello

    I have a class that extends the dialog box. A few Radiobuttns are added. I want to get the value of the RadioButton selected the actual class of the screen, call the dialog box by clicking the Dialog.OK button. The code I tried is as follows:

    My class of the screen:

                    XXXDialog clScrn = new XXXDialog ();
                    if (clScrn.doModal() == Dialog.OK) {
    
                        // I click Ok, but this is never shown
                        Dialog.alert("Closed & here");
                        Dialog.alert("Selected = " + clScrn.getSelectedItem());
                    }
                    clScrn = null;
    

    The dialog class-

      public XXXDialog() {
            super(Dialog.D_OK, "Select Item", Dialog.OK, null, VERTICAL_SCROLL | VERTICAL_SCROLLBAR | Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT);
            rbg = new RadioButtonGroup();
            rb1 = new RadioButtonField("One", rbg, false, Field.USE_ALL_WIDTH);
            rb2 = new RadioButtonField("Two", rbg, false, Field.USE_ALL_WIDTH);
    
            rb1.setChangeListener(this);
            rb2.setChangeListener(this);
    
            add(rb1);
            add(rb2);
        }
    
        public void fieldChanged(Field f, int context) {
    /*
    Actually, I want to know which field was clicked RadioButton or Ok button. If it is Ok, then I want to hide and return back to screen.
    */
    
            try {
                    RadioButtonField fd = (RadioButtonField) f;
                    item = fd.getLabel();
                    System.out.println("Selected = " + item);
            } catch (Exception e) {
            }
    
            try{
                ButtonField fd = (ButtonField) f;
                System.out.println("********* Button PRESSED = " + f);
                this.close();
            } catch (Exception e) {
            }
    
            System.out.println("*********** Field Count = " + f.getManager().getFieldCount() + " Index = " + f.getIndex());
        }
    
        public String getSelectedItem() {
            return item;
        }
    

    The XXXDialog class is in a separate file of java.

    Can anyone help me on what to do and how to achieve the goal.

    Thank you

    I found my solution. What I did is: -.

    In my main screen, I call the as dialog box

    clScrn.doModal ();

    Dialog.Alert (Come Back here");   I see this alert as soon as the dialog box is closed.

    In my class of dialogue, I have only the Ok button, dialog can be closed using the ESC key as I implemetned the code-

    Dialog box does not close on ESC
    {} public boolean keyChar (key char, int status, int time)
    Boolean retVal = false;
    {Switch (Key)}
    case Characters.ESCAPE:
    break;
    }
    Return retVal;
    }

    So now, there is no other means to close the exception, Ok button dialog box and I make sure that when Ok is clicked, 1 radiobutton is selected.

    Thank you all for the time and effort.

  • CustomTextBox align

    Hi all

    I use code kindly offered online by Dorian.

    Now, I am trying to align this text box toward the Center.

    Does anyone know what I need to change to achieve this please?

    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.component.EditField;
    import net.rim.device.api.ui.component.BasicEditField;
    import net.rim.device.api.system.EncodedImage;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.system.Characters;
    import net.rim.device.api.math.Fixed32;
    import net.rim.device.api.ui.DrawStyle;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.container.MainScreen;
    
    public class CustomTextBox2 extends Manager{    /**     * Default margins     */
        private final static int DEFAULT_LEFT_MARGIN = 0;
    
    private final static int DEFAULT_RIGHT_MARGIN = 10;
    private final static int DEFAULT_TOP_MARGIN = 5;
    private final static int DEFAULT_BOTTOM_MARGIN = 5;        /**     * Default paddings     */
    private final static int DEFAULT_LEFT_PADDING = 10;
    private final static int DEFAULT_RIGHT_PADDING = 10;
    private final static int DEFAULT_TOP_PADDING = 5;
    private final static int DEFAULT_BOTTOM_PADDING = 5;
    /**     * Margins around the text box     */
    private int topMargin = DEFAULT_TOP_MARGIN;
    private int bottomMargin = DEFAULT_BOTTOM_MARGIN;
    private int leftMargin = DEFAULT_LEFT_MARGIN;
    private int rightMargin = DEFAULT_RIGHT_MARGIN;
    /**     * Padding around the text box     */
    private int topPadding = DEFAULT_TOP_PADDING;
    private int bottomPadding = DEFAULT_BOTTOM_PADDING;
    private int leftPadding = DEFAULT_LEFT_PADDING;
    private int rightPadding = DEFAULT_RIGHT_PADDING;
    /**     * Amount of empty space horizontally around the text box     */
    private int totalHorizontalEmptySpace = leftMargin + leftPadding
            + rightPadding + rightMargin;
    /**     * Amount of empty space vertically around the text box     */
    private int totalVerticalEmptySpace = topMargin + topPadding
            + bottomPadding + bottomMargin;
    /**     * Minimum height of the text box required to display the text entered     */
    private int minHeight = getFont().getHeight() + totalVerticalEmptySpace;
    /**
     * Width of the text box     */
    private int width;
    /**     * Height of the text box     */
    private int height = 45;
    /**     * Background image for the text box     */
    private EncodedImage backgroundImage;
    /**     * Bitmap version of the backgroundImage.
     * Needed to reduce the calculation overhead incurred by
     * scaling of the given image
     * and derivation of Bitmap from the
     * EncodedImage every time it is needed.
     */
    private Bitmap bitmapBackgroundImage;
    /**
     * The core element of this text box
     */
    private EditField editField;
    MainScreen theScreen;
    //private BasicEditField editField;
    //private String entireText;
    public CustomTextBox2(int width2, int height, MainScreen aScreen)
    {
         super(0);
        theScreen = aScreen;
        // Let the super class initialize the core
    
        width = width2 + 20;
        // An edit field is the sole field of this manager.
        editField = new EditField();
        //editField = new CustomEditField();
        add(editField);
    }
    
    /*
    public CustomTextBox2(EncodedImage backgroundImage)
    {
        this();
    
    setBackgroundImage(backgroundImage);
        }
     * */
    
        public void setSize(int width, int height)
        {
            boolean isChanged = false;
            if (width > 0 // Ignore invalid width
                    && this.width != width)
            {
                this.width = width;
                isChanged = true;
            }
            // Ignore the specified height if it is less
            // than the minimum height required to display the text.
            if (height > minHeight && height != this.height)
            {
                this.height = height;
                isChanged = true;
            }
            // If width/height has been changed and background image
            // is available, adapt it to the new dimension
            if (isChanged == true && backgroundImage != null)
            {
                bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                        this.width - (leftMargin+rightMargin),
                        this.height - (topMargin+bottomMargin));
    
            }
        }
    
        public void setWidth(int width)
        {
            if (width > 0 && width != this.width)
            {
                this.width = width;
                // If background image is available, adapt it to the new width
                if (backgroundImage != null)
                {
                    bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                            this.width - (leftMargin+rightMargin),
                            this.height - (topMargin+bottomMargin));
                }
            }
        }
        public void setHeight(int height)
        {
            // Ignore the specified height if it is
            // less than the minimum height required to display the text.
            if (height > minHeight)
            {
                this.height = height;
                // If background image is available, adapt it to the new width
    
                if (backgroundImage != null)
                {
                    bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                            this.width - (leftMargin+rightMargin),
                            this.height - (topMargin+bottomMargin));
                }
            }
        }
        public void setBackgroundImage(EncodedImage backgroundImage)
        {
            this.backgroundImage = backgroundImage;
            // Consider the height of background image in
            // calculating the height of the text box.
            // setHeight() does not ensure that specified
            // height will be in effect, of course, for valid reasons.
            // So derivation of Bitmap image in the setHeight() method is not sure.
            setHeight(backgroundImage.getHeight() + topMargin + bottomMargin);
            if (bitmapBackgroundImage == null)
            {
                bitmapBackgroundImage = getScaledBitmapImage(backgroundImage,
                        this.width - (leftMargin+rightMargin),
                        this.height - (topMargin+bottomMargin));
            }
        }
        /**     * Generate and return a Bitmap Image scaled according
         * to the specified width and height.
         *
         * @param image     EncodedImage object
         * @param width     Intended width of the returned Bitmap object
         * @param height    Intended height of the returned Bitmap object
         * @return Bitmap object     */
        private Bitmap getScaledBitmapImage(EncodedImage image, int width, int height)
        {
            // Handle null image
            if (image == null)
            {
                return null;
            }
            int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
            int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
            int requiredWidthFixed32 = Fixed32.toFP(width);
            int requiredHeightFixed32 = Fixed32.toFP(height);
            int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
            int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
            image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
            return image.getBitmap();
        }
        protected void sublayout(int width, int height)
        {
            // We have one and only child - the edit field.
            // Place it at the appropriate place.
            Field field = getField(0);
            layoutChild(field, this.width - totalHorizontalEmptySpace,
                    this.height - totalVerticalEmptySpace);
            setPositionChild(field, leftMargin+leftPadding, topMargin+topPadding);
            setExtent(this.width, this.height);
        }
        public void setTopMargin(int topMargin)
        {
            this.topMargin = topMargin;
        }
        public void setBottomMargin(int bottomMargin)
        {
            this.bottomMargin = bottomMargin;
        }
        protected void paint(Graphics graphics)    {
            // Draw background image if available, otherwise draw a rectangle
            if (bitmapBackgroundImage == null)
            {
                //graphics.drawRect(leftMargin, topMargin,                                 width - (leftMargin+rightMargin),                                 height - (topMargin+bottomMargin));
                graphics.setColor(0x000000);
                graphics.drawRoundRect(leftMargin, topMargin,
                        width - (leftMargin+rightMargin),
                        height - (topMargin+bottomMargin), 15, 15);
                graphics.setColor(0xffffff);
                graphics.fillRoundRect(leftMargin, topMargin,
                        width - (leftMargin+rightMargin),
                        height - (topMargin+bottomMargin), 15, 15);
            }
            else
            {
                graphics.drawBitmap(leftMargin, topMargin,
                        width - (leftMargin+rightMargin),
                        height - (topMargin+bottomMargin),
                        bitmapBackgroundImage, 0, 0);        }
            // Determine the rightward text that can fit into the visible edit field
            EditField ef = (EditField)getField(0);
            String entireText = ef.getText();
            boolean longText = false;
            String textToDraw = "";
            Font font = getFont();
            int availableWidth = width - totalHorizontalEmptySpace;
            if (font.getAdvance(entireText) <= availableWidth)
            {
                textToDraw = entireText;
            }
            else
            {
                int endIndex = entireText.length();
                for (int beginIndex = 1; beginIndex < endIndex; beginIndex++)
                {
                    textToDraw = entireText.substring(beginIndex);
                    if (font.getAdvance(textToDraw) <= availableWidth)
                    {
                        longText = true;
                        break;
                    }            }        }
            if (longText == true)
            {
                // Force the edit field display only the truncated text
                ef.setText(textToDraw);
                // Now let the components draw themselves
                super.paint(graphics);
                // Return the text field its original text
                ef.setText(entireText);
    
            }
            else
            {
                super.paint(graphics);
            }
        }
        public int getPreferredWidth()
        {
            return width;
        }
        public int getPreferredHeight()
        {
            return height;
        }
        protected boolean keyChar(char ch, int status, int time)
        {
           Log.info("KEYCHAR " + ch);
            switch(ch){
    
                case Characters.ENTER:
                    try
            {    Log.info("KEYCHAR 1");
                       // theScreen.textButton.getChangeListener().fieldChanged(theScreen.textButton, theScreen.textButton.getIndex());
       Log.info("KEYCHAR 2");
              // f.getChangeListener().fieldChanged(f, f.getIndex());
            }
            catch (Exception e)
            {
            Log.info("Error at fcn" + e);
            }
                    return true;
    
            }
    Log.info("KEYCHAR 0");
    //theScreen.textButton.getChangeListener().fieldChanged(theScreen.textButton, theScreen.textButton.getIndex());
    
            return super.keyChar(ch,status,time);
        }
        public String getText()
        {
            return ((EditField)getField(0)).getText();
        }
        public void setText(final String text)
        {
            ((EditField)getField(0)).setText(text);
        }
       }
    

    You are missing a centerpiece - the ability to set the bits of style on this field. If you add a constructor that accepts a parameter of long style and has great (style) as the first operator, you should be able to create with the FIELD_HCENTER style bit and add it to a Manager honor this indicator (for example, VerticalFieldManager).  Then it will be automatically centered horizontally by the parent Manager.

    It is the same on FIELD_VCENTER and, say, HorizontalFieldManager.

  • Selected index was not found in the editfield

    Hello

    I am facing a problem when adding listener to the BasicEditField. I'm not able to retrieve the index of the field in which the data has been inserted. I'm getting the same index for each field. Here is the corresponding code.

    BasicEditField[] quantField=new BasicEditField[10];
    quantField[i]=new BasicEditField("","",10,BasicEditField.FILTER_INTEGER | BasicEditField.NO_NEWLINE);
    quantField[i].setChangeListener(new FieldChangeListener(){
        public void fieldChanged(Field field, int context) {
            Dialog.alert("selected:"+field.getIndex());
        }
    });
    

    Please, help me in this issue.

    just to add to your options, you can use set/getCookie to identify the fields that have been added anonymously.

  • More tips for optimization for a novice?

    Hello

    I started with a small project in java of BB a few weeks ago. The program is now complete in features. And I would make him feel snappy.

    The program searches the remote address book contacts using email or the name from fields to address a message. Some e-mails have many contacts to: or CC: fields. Through each of them obviously takes a lot of time Blackberry 9700 API 5.0 processor.

    Currently, it takes up to 5 seconds to make 25 contacts. It feels too and I don't want to bother showing the hourglass for this basic action. I already checked and applied the advice in this topic http://supportforums.blackberry.com/t5/Java-Development/Aggressive-Optimization/m-p/122606#M13797

    Can you think of other optimization that I could use for the part below?

    Thank you very much for your advice!

    Diego

    Basically, there are two methods to get the emails and names of e-mail net.rim.blackberry.api.mail.Message. Then I call them for all types of message fields in a style loop "copypaste". This information is shown on a user and program acts on his choice.

        private void addAddressChoiceField(int currentType, String currentTypeString, final net.rim.blackberry.api.mail.Message message){        try {            int numberOfRecipients = message.getRecipients(currentType).length;            if(numberOfRecipients>0){ //not adding empty fields at all                String[] addressList = new String[numberOfRecipients];                for (int i=numberOfRecipients-1 ;i>=0; i-- ){ //this iteration style should speed up a little                        addressList[i]= message.getRecipients(currentType)[i].getAddr();                }                ClickableObjectChoiceField ocf = new ClickableObjectChoiceField(currentTypeString,addressList);                this.add(ocf);                ocf.setChangeListener(this);            }             } catch (Exception e) {            Dialog.alert(e.toString());        }    }
    
        private void addNameChoiceField( int currentType, String currentTypeString, final net.rim.blackberry.api.mail.Message message){        try {            int numberOfRecipients = message.getRecipients(currentType).length;            if(numberOfRecipients>0){ //not adding empty fields at all                int namesListLength = 0;                        String[] interimNamesList = new String[numberOfRecipients];                for (int i=numberOfRecipients-1 ;i>=0; i-- ){ //this iteration style should speed up a little                    if( message.getRecipients(currentType)[i].getName() instanceof String) { // i.e. not null                        interimNamesList[namesListLength++]= message.getRecipients(currentType)[i].getName() ;                    }                }                   String[] addressList= new String[namesListLength];                for (int i=namesListLength-1; i>=0; i-- ){ addressList[i]= interimNamesList[i];  } // now addressList should not have any null strings                ClickableObjectChoiceField ocf = new ClickableObjectChoiceField(currentTypeString,addressList);                this.add(ocf);                ocf.setChangeListener(this);            }             } catch (Exception e) {            Dialog.alert(e.toString());        }    }
    
        public void update(final net.rim.blackberry.api.mail.Message message) {        String from_address;        try { from_address= message.getFrom().getAddr(); } catch (Exception ex) { from_address=""; }        user_input = new EditField("Lookup: ",from_address    );        //TODO substitute with the pop-up text field like in the vanilla lookup from the address book.        user_input.setBorder(BorderFactory.createRoundedBorder( new XYEdges(10,10,10,10)));        add(user_input);        add(new RichTextField("Chose from Contact Address(es):"));        // using the predefined method in a copypaste loop through email address fields        addAddressChoiceField(Message.RecipientType.FROM, "From:", message);        addAddressChoiceField(Message.RecipientType.TO, "To:", message);        addAddressChoiceField(Message.RecipientType.CC, "CC:", message);        addAddressChoiceField(Message.RecipientType.BCC, "BCC:", message);        addAddressChoiceField(Message.RecipientType.REPLY_TO, "Reply_To:", message);        addAddressChoiceField(Message.RecipientType.SENDER, "Sender:", message);        add(new RichTextField("Chose from Contact Name(s)"));        addNameChoiceField(Message.RecipientType.FROM, "From:", message);        addNameChoiceField(Message.RecipientType.TO, "To:", message);        addNameChoiceField(Message.RecipientType.CC, "CC:", message);        addNameChoiceField(Message.RecipientType.BCC, "BCC:", message);        addNameChoiceField(Message.RecipientType.REPLY_TO, "Reply_To:", message);        addNameChoiceField(Message.RecipientType.SENDER, "Sender:", message);        UiApplication.getUiApplication().pushScreen(this);      }
    

    Here is the ObjectChoiceField just in case that is important.

     package com.diegor.contextLookup;
    
    import net.rim.device.api.ui.component.ObjectChoiceField;
    
    import net.rim.device.api.system.KeypadListener;
    
    final public class ClickableObjectChoiceField extends ObjectChoiceField implements KeypadListener  {
    
       public ClickableObjectChoiceField() {
    
           super();
    
            // TODO Auto-generated constructor stub
    
     }
    
       public ClickableObjectChoiceField(String label, Object[] choices,
    
               int initialIndex, long style) {
    
         super(label, choices, initialIndex, style);
    
         // TODO Auto-generated constructor stub
    
     }
    
       public ClickableObjectChoiceField(String label, Object[] choices,
    
               int initialIndex) {
    
         super(label, choices, initialIndex);
    
            // TODO Auto-generated constructor stub
    
     }
    
       public ClickableObjectChoiceField(String label, Object[] choices,
    
               Object initialObject) {
    
         super(label, choices, initialObject);
    
           // TODO Auto-generated constructor stub
    
     }
    
       public ClickableObjectChoiceField(String label, Object[] choices) {
    
         super(label, choices);
    
          // TODO Auto-generated constructor stub
    
        }
    
       public boolean navigationUnclick(int status, int time) {
    
            this.getChangeListener().fieldChanged(getOriginal(), getIndex());
    
           return super.navigationClick(status, time);
    
     }
    
    }
    

    In your loop, I noticed that you frequently call message.getRecipients (...).  Not sure how long takes every call, but you can definitely optimize your code by calling which, once by setting a local variable on each iteration of the loop, then using this variable instead.

  • get a label width c ++

    import bb.cascades 1.2
    
    Page {
    
        Container {
            background: Color.LightGray
    
            Container {
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                topPadding: 250.0
                Label {
                    id: dropLabel
                    objectName: "dropLabel"
                    text: "Select your country from the list below"
                    textStyle {
                        base: SystemDefaults.TextStyles.TitleText
                        textAlign: TextAlign.Center
                        color: Color.Black
                    }
                }
                    DropDown {
                        objectName: "dropList"
                        selectedIndex: quoteApp.getIndex();
                        preferredWidth: quoteApp.getWidth();
                        Option {
                            text: "10 min"
                            description: "Sets the alarm to 10 minutes"
                            value: "10min"
                        }
    
                        // text only
                        Option {
                            text: "15 min"
                            value: "15min"
                        }
    
                    }
                }
                Container {
                    layout: StackLayout {
                        orientation: orientation.RightToLeft
                    }
    
                    horizontalAlignment: HorizontalAlignment.Center
                    verticalAlignment: VerticalAlignment.Center
                            CheckBox {
                                objectName: "remember"
                                preferredWidth: 500
                                text: "Remember me"
    
                            }
                        }
            Container {
    
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                    Button {
                            onClicked: {
                                quoteApp.clickedButton();
    
                            }
                            text: "Submit"
    
                        }
                }
    
        }
    
    }
    

    http://S12.postimg.org/5rwtgd66j/Server_Selection.PNG

    I want to put this page. I want to do the drop as width that select your country from the list below.

    so why do I try part in bold

    float ApplicationUI::getWidth()
    {
    Label * lb = root->findChild ("dropLabel");
    return lb--> preferredwidth():

    }

    but the app crashes on preffferredwqidth

    How can I solve this?

    Someone also suggestiong to replace toppadding:250.0 for this page? It is good to use?

    Look at spaceQuotas instead of hard coded values for the positioning of the controls...

    http://developer.BlackBerry.com/native/documentation/Cascades/UI/layouts/

    The width of an object can be found by attaching a layoutUpdateHandler...

    http://developer.BlackBerry.com/native/reference/Cascades/bb__cascades__layoutupdatehandler.html

  • ObjectChoiceField need help!

    Hello

    I use two filed subject choice form and one is linked with the other as

    You must select an option in the first field of choice, then on the basis of the selected value, you need to load the other values in the second field of choice.

    Everything works well except a little problem in the second field.

    When I select the second field he through exception of null pointer after showing the last element. It is not showing me the first item again when I press the space bar.

    You can't understand my problem.

    I paste the code here.

    ' Public Sub fieldChanged (field field, int context)
    {
    int count = this.getFieldWithFocusIndex ();
    int index1 = field.getIndex ();
    If (this.getFieldWithFocusIndex () == 1)
    {
            
    System.out.println ("control in fieldChanged =" + field);
    ObjectChoiceField objField = field (ObjectChoiceField);
    selectedAssetTypeId = (objField.getSelectedIndex () + 1;
    System.out.println ("selected index =" + selectedAssetTypeId);
    VF1 = specificationPanel ();
    }
                            
    }

    I have created objectchoicefield first in the constructor, and then creating 2 choicefield using a method to load the related values, here's this method.

    private VerticalFieldManager specificationPanel()
    {
             
    System.out.println ("Control in specificationPanel");
    vf.deleteAll ();
            
            
    Vector assetTypeSpecVector;
      
    SpecificationArray String().
    assetTypeSpecVector = new Vector();
            
    Try
    {
     
    ResultSet rs = dataAccess.ExecuteQuery ("SELECT spec_desc FROM AssetTypeSpecification Where atype_id =" + selectedAssetTypeId);
                   
    While (RS. Next
    {
    assetTypeSpecVector.addElement ("" + rs.getString (0));
    System.out.println ("get spec db =" + rs.getString (0));
    }
           
    } catch (ULjException uex) {}
    System.out.println ("ULjException AssetTypeSpecVector:"+ uex.toString () ');
    }
    catch (Exception ex) {}
    System.out.println ("Exception: in getAssetTypeSpecVector"+ ex.toString () ');
    }
    specificationArray = new String [assetTypeVector.size ()];
    int count = 0;
    for (Enumeration e = assetTypeSpecVector.elements (); e.hasMoreElements () ;))
    {
    specificationArray [count] = (e.nextElement ()) m:System.NET.SocketAddress.ToString ();
    Count ++;
    }
            
                      
    selectSpecificationObj = new ObjectChoiceField ("Select specification:", specificationArray);
    selectSpecificationObj.setChangeListener (this);
    selectSpecificationObj.setSelectedIndex (0);
    VF1. Add (selectSpecificationObj);
    return vf1;
    }

    "I must use vector -" don't mind the use of the vector, is the enumerator for the vector which is not necessary.

    "Vector's y attach another element which is null at the end"-does that mean it is resolved?  Can then mark you?

    "I don't know why"-null columns in the database?

  • What field in ApplicationDescriptor is unique

    What field in ApplicationDescriptor is unique?

    Javadoc, getIndex() function must be unique. but, I see that each getIndex() value is 0.

    However, getModuleHandle() function gives different numbers. It is perhaps unique? or how can I unique field for each application?

    getModuleHandle should give a unique value for each particular application installed on a BlackBerry smartphone. However, these values are not directly to an application, which means that if you get the handle of the module for the same application on an another BlackBerry smartphone you will probably get a different value.

  • Not able to focus BitmapField

    Hi gurus

    I searched for this error but have not been able to find a solution.

    I have a HorizontalFieldManager where I add BitmapFields. These BitmapFields have FOCUSABLE, no problem with that style.

    What I'm trying to do, it is only when the user focuses on a different field, outside the HorizontalFieldManager and then returns to the HorizontalFieldManager, enforcement "remembers" field was centered in the HorizontalFieldManager, much as the menus of Twitter and Facebook on their BB applications.

    To do this, I'm saving SelectedIndex when the Manager is blurry:

       protected void onUnfocus(){
            BitmapField focusedField = (BitmapField) getFieldWithFocus();
            if (focusedField != null) selectedIndex = focusedField.getIndex();      
    
            super.onUnfocus();
        }
    

    It works very well, I'm able to get the selectedIndex property. So what I try to do next is to focus this field when the manager gets concentrate:

     protected void onFocus(int direction) {     
    
            BitmapField fieldToFocus = (BitmapField) getField(selectedIndex);
            if (fieldToFocus != null) fieldToFocus.setFocus();              
    
            super.onFocus(direction);
        }
    

    I see that fieldToFocus is recovered succcesfully, is not null and the selectedIndex property is valid, but when I run the method

    fieldToFocus.setFocus()
    

    It is for me a StackOverflow Exception.

    I tried many other ways and have not been able to understand how to fix it. I also tried to comment the last line on the onFocus event: super.onFocus (branch);

    But it does not work.

    Help, please!

    a Board exception stackoverflow on a loop without end. maybe onFocus is called again when you run setFocus? Avoid it along with a check on the target area.

    I would also call great.

Maybe you are looking for

  • Lost access to iTune movies

    Older movies purchased on iTunes is no longer will play with checked Apple ID and recognized password, how can I update the movie file to play.

  • I have Mozilla firefox 38.0.1, so I can uninstall 30.0?

    The only problem is that if worm 30.0 is not necessary to use the 38.0.1 worm, I would like to release the 69 megs, it takes on the hard drive.

  • Portege R700 - DVD region unlock

    I have a R700 and the dvd is set to region 1 and as I live in Australia (region 4) and I'll be traveling abroad and observe overthere DVD. The manual says I can only change the region a few times before it locks in this region. I was wondering how ca

  • HP laptop - 15-ac118tu: Wifi &amp; LAN Driver unavailable

    Hello I brought HP for laptop - 15-ac118tu three days ago. There is no drivers for this product for Wifi/Lan on the HP site. Here is the link to download the drivers: http://support.HP.com/in-en/drivers/selfservice/HP-15-notebook-PC-series/8499326/mo

  • Windows 8 Lenovo Y480 bootloader problem

    Hi, I recently bought a Lenovo Y480 preloaded with Windows 8. I reduced the size of the partition of Windows 8 to make a new partition for a new installation of Ubuntu 12.04. Figured, GRUB has messed up the bootloader and I simply can't boot into Win