HorizontalFieldManager problem

I want to add fields to the horizontalFieldManager by defining their position as

HorizontalFieldManager never respect the horizontal alignment - of course, because he has his own approach to horizontal placement. The best thing to do then import the JustifiedEvenlySpacedHorizontalFieldManager of

Implement advanced buttons, fields and managers

The code has a multitude of other great user interface code, so be sure to keep somewhere very practice.

You can also experiment with setting the margins on your domains or creating fields of spacer and adding spacers Fluxsol between your gadgets actually used.

Tags: BlackBerry Developers

Similar Questions

  • several checkbox in horizontalfieldmanager problem!

    Hi, I add several checkbox in horizontal fieldmanager.

    It displays as intended for os 5 and less but only displays the first box added to os 6.

    I don't know what the problem is! Please tell me what I'm doing wrong, or give me a work-around!

    Code:

    check1 = new CheckboxField("1", true);
    check2 = new CheckboxField("2", true);
    check3 = new CheckboxField("3", true);
    
    checkField = new HorizontalFieldManager();
    
    checkField.add(check1);
    checkField.add(check2);
    checkField.add(check3);
    
    add(checkField);
    

    Thanks in advance!

    It seems that in CheckboxField became "width-hungry" the OS 6.  Check this thread for the solution:

    CheckboxField, on the same line with OS6

  • Development/unfocus HorizontalFieldManager problem

    I do this on a HorizontalFieldManager to focus and unfocus color and his works fine. But my doubt is that even if I do my style of hfm like NON_FOCUSABLE, it always shows the unfocus color focus which shudnt be the case. Kindly help

    protected void paintBackground(Graphics g) {
            if (isFocus()) {
                int[] drawColors = { 0x1a66b4, 0x1a66b4, 0x1a66b4, 0x1a66b4, 0x1a66b4, 0x1a66b4, 0x4b80b7, 0x4b80b7, 0x4b80b7, 0x4b80b7, 0x4b80b7, 0x4b80b7 };
                g = Gradient.draw(g, mHeight, mWidth, drawColors);
            } else {
                int[] drawColors = { color, color, color,color,color,color,color,color,color,color,color,color};
                g = Gradient.draw(g, mHeight, mWidth, drawColors);
            }
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
        }
    
        public void onFocus(int direction) {
            super.onFocus(direction);
            invalidate();
    
        }
    

    Hey I solved it

  • Custom HorizontalFieldManager problem focusable

    I had a VerticalFieldManager with a list of items.

    Each element is a HorizontalFieldManager custom, composed by other fields. These custom fields are FOCUSABLE by manufacturer.

    I would like to have the first element of the list selected/focused when I view my list of items.

    If I try to set focus on the first point of

    firstItem.setFocus)

    nothing seems to be happening: the debbugger says "FocusHistory: Focus acquired; App Tesssst; Component TestScreen.

    TestScreen is

    public class TestScreen extends MainScreen{
    
        BitmapField _placeholder;
    
        public TestScreen() {
            super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
    
            Background tiledBG = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("grey_tile.png"), Background.POSITION_X_LEFT, Background.POSITION_Y_TOP, Background.REPEAT_BOTH);
    
            getMainManager().setBackground(tiledBG); 
    
            HorizontalFieldManager horizontal = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL|NO_HORIZONTAL_SCROLLBAR);
            CustomVerticalManager listVerticalContainer = new CustomVerticalManager(VERTICAL_SCROLL|NO_VERTICAL_SCROLLBAR);
    
            add(horizontal);
            horizontal.add(listVerticalContainer);      
    
            for(int i=0; i<19; i++){
                _placeholder = new BitmapField(Bitmap.getBitmapResource("imageplaceholder.png"));
    
                HorizontalItemField item = new HorizontalItemField(_placeholder, "ASD", "sukapub", 2, "100$", FOCUSABLE);
                listVerticalContainer.add(item);
                if(i == 0) item.setFocus();
            }
    
            System.out.println("@#@#@# FOCUSED ITEM = "+getFieldWithFocus());
    
        }
    

    This one:

    System.out.println("@#@#@# FOCUSED ITEM = "+getFieldWithFocus());
    

    Returns:

    @# @ #@ # AXÉ ITEM = null

    Firstly, FOCUSABLE is supposed on connectors and downloaders - only fields.  If a manager has any focusable inside fields, its setFocus() will find the first such focus area and set to it. Compare the getFieldWithFocus() and the getLeafFieldWithFocus() to see the difference. In all cases, make sure that your _itemDetails is created focusable.

    Second, I noticed that you do not add _name, _publisher _price to your manager. Your sublayout is not also remove those. I can only imagine you send these fields to be placed somewhere else or

    Thirdly, given that you override sublayout anyway, consider the extension Manager rather than HorizontalFieldManager.  You can also use setMargin _image and _itemDetails drop sublayout() in total.  Even if Field.setMargin was documented in OS 6.0, he works since pretty much forever (my guess is since 4.0.0 - version where XYEdges appeared).

    Fourth - onFocus and onUnfocus managers are odd to say, I wouldn't count on them. onUnfocus, in particular, is wrong even in areas - could not get called at all. Use FocusChangeListener to detect the focus moves. Just add 'implements FocusChangeListener' to your class definition, implement ' public Sub focusChanged (field field, int eventType) and invoke setChangeListener (this) somewhere in the constructor. Respond to the types of FOCUS_LOST and FOCUS_GAINED events inside focusChanged and buttonColor and textColor changes - and don't forget invalidate()!

  • Addition of two basicEditFields in HorizontalField Manager

    I try to add two basic change fields in a Horizontal field Manager. But, I don't know why, that one field is in veiw cannot see the second field anywhere. Here is the code I use:

     HorizontalFieldManager hfm ;
        VerticalFieldManager signUpMngr;
        BasicEditField cc, number;
        int width = (((Display.getWidth()*25)/100)-20);
        public UserScreen() {
            cc = getBasicEditField(4, BasicEditField.FILTER_NUMERIC,width ,5, 5, 5, 5);
            number = getBasicEditField(11, BasicEditField.FILTER_NUMERIC,width ,5, 5, 5, 5);
    
            hfm = new HorizontalFieldManager(USE_ALL_WIDTH|NO_HORIZONTAL_SCROLL|NO_VERTICAL_SCROLL){
    protected void sublayout(int maxWidth, int maxHeight) {
        // TODO Auto-generated method stub
        super.sublayout(maxWidth, maxHeight);
        int count = getFieldCount();
        int x = 20;
        int y = 10;
        for (int i = 0; i < count; i++) {
        Field f = getField(i);
        layoutChild(f, f.getWidth(), f.getHeight());
        setPositionChild(f, x, y);
        x += cc.getWidth()+5;
        }
                       setExtent(Display.getWidth(),Display.getHeight());
       }
    };
        hfm.add(cc);
        hfm.add(number);
    
       signUpMngr = new VerticalFieldManager(USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
       signUpMngr.add(hfm);
    
       this.add(signUpMngr);
    }
    
    public BasicEditField getBasicEditField(final int size, final long style,final int fieldWidth, final int topPadding, final int rightPadding,final int bottomPadding, final int leftPadding) {
      BasicEditField field = new BasicEditField("", "", size, style) {
        protected void paint(Graphics graphics) {
               graphics.setColor(Color.GRAY);
           getFont().derive(Font.BOLD);
           super.paint(graphics);
        }
    
        protected void paintBackground(Graphics g) {
           g.setColor(Color.GRAY);
           g.drawRoundRect(leftPadding, 0, fieldWidth- (leftPadding + rightPadding), this.getHeight(), 12,14);
           super.paintBackground(g);
            }
      };
      field.setPadding(topPadding, rightPadding + 2, bottomPadding,
                    leftPadding + 2);
      return field;
     }
    

    Concerning

    Here's the answer to your problem:

    HorizontalFieldManager problem

  • List of the HorizontalFieldManager with scrolling focus problem

    Hello

    I'm doing a vertical list of horizontalfieldmanager with an icon and two text fields, but I'm having a problem when scrolling it. I used a nullField to manage focus. When I scroll to the top everything works well, but when I Ahmed to the bottom of the item appears on the edge of the screen.

    I guess that I did not understand how to manage the focusChange metodh and the metodh of the painting.

    All advice will be appreciated.

    Thank you, Andrea.

    //
        // Main screen for the application
        //
        private class MyMainScreen extends MainScreen
        {
            public MyMainScreen()
            {
                super(Manager.USE_ALL_WIDTH);
    
                for (int i = 0; i<20; i++) this.getMainManager().add(new PanelRow("off", "first text line", "second text line"));
            }
    
            private class PanelRow extends HorizontalFieldManager implements FocusChangeListener
            {
                private NullField nullField;
                private BitmapField icon;
                private ColorLabelField label1;
                private ColorLabelField label2;
    
                public PanelRow(String iconString, String label1String, String label2String)
                {
                    super(Manager.USE_ALL_WIDTH);
    
                    // Add null field
                    nullField = new NullField(NullField.FOCUSABLE);
                    nullField.setFocusListener(this);
                    super.add(nullField);
    
                    // Add bitmap
                    Bitmap offIcon = Bitmap.getBitmapResource("offButton.png");
                    icon = new BitmapField(offIcon, BitmapField.NON_FOCUSABLE | BitmapField.FIELD_LEFT);
                    super.add(icon);
    
                    // Add first and second text lines
                    VerticalFieldManager labelsVerticalManager = new VerticalFieldManager();
                    label1 = new ColorLabelField(label1String, LabelField.NON_FOCUSABLE | LabelField.FIELD_LEFT);
                    label2 = new ColorLabelField(label2String, LabelField.NON_FOCUSABLE | LabelField.FIELD_LEFT);
                    labelsVerticalManager.add(label1);
                    labelsVerticalManager.add(label2);
                    super.add(labelsVerticalManager);
                }
    
                public void focusChanged(Field field, int eventType)
                {
                    invalidate();
                }
    
                protected boolean navigationClick(int status, int time)
                {
                    fieldChangeNotify(FieldChangeListener.PROGRAMMATIC);
    
                    return true;
                }
    
                protected void paint(Graphics g)
                {
                    int oldBackground = g.getBackgroundColor();
    
                    if (nullField.isFocus())
                    {
                        g.setBackgroundColor(Color.CADETBLUE);
    
                        label1.setFontColor(Color.WHITE);
                        label2.setFontColor(Color.WHITE);
                    }
                    else
                    {
                        g.setBackgroundColor(Color.WHITE);
    
                        label1.setFontColor(Color.SLATEGRAY);
                        label2.setFontColor(Color.BLACK);
                    }
    
                    g.clear();
    
                    g.setBackgroundColor(oldBackground);
    
                    super.paint(g);
                }
            }
    
            //
            // Define a new colored labelfield class
            //
            public class ColorLabelField extends LabelField
            {
                public ColorLabelField(Object text, long style)
                {
                    super(text, style);
                }
    
                private int mFontColor = -1;
    
                public void setFontColor(int fontColor)
                {
                    mFontColor = fontColor;
                }
    
                protected void paint(Graphics graphics)
                {
                    if (-1 != mFontColor) graphics.setColor(mFontColor);
    
                    super.paint(graphics);
                }
            }
        }
    

    Then try to create your NullField with getFocusRect override: like this:

    nullField = new NullField(NullField.FOCUSABLE) {
      public void getFocusRect(XYRect rect) {
        getManager.getExtent(rect);
        rect.setLocation(0, 0);
      }
    };
    

    Paint won't help you - you must tell the system to the entire span developed in order to scroll properly. If the above fails, analyze your focusChanged eventType and make sure that your Manager is fully visible on the screen on FOCUS_GAINED. To do this, you need to use getManager () .getVerticalScroll () / getManager () .setVerticalScroll () as well as of your Manager and getHeight() getTop().

  • Strange problem with HorizontalFieldManager - it does not show on real device bitmap

    I have a rather strange problem with the HorizontalFieldManager on my Blackberry 8820, which I did not on the Simulator, or done other blackberries that I tried to install my game.

    The problem is that bitmaps that I add, do not appear on the actual device, as in the images below. The code is provided below as well. No idea how to debug, or resolve is appreciated.

    Here's what I see on Simulator and some devices

    Here's what I see on the real blackberry:

    Code:

    ......

    OK, I found the solution - the problem is that there seems to be a bug where you can't put more fields button radio on a horizontal layout manager with 4.2.2.x.

    The solution is to extend the RadioButtonField field and replace the positioning method:

    RadioButtonField radioField = new RadioButtonHack ("", textureGroup, isSelected);

    SerializableAttribute public class RadioButtonHack extends RadioButtonField {}

    public RadioButtonHack() {}
    Super();
    }

    public RadioButtonHack (String label, group RadioButtonGroup,
    Boolean selected, long style) {}
    Super (label, group, selected, style);
    }

    public RadioButtonHack (String label, group RadioButtonGroup,
    Boolean selected) {}
    Super (label, selected group);
    }

    public RadioButtonHack (label As String) {}
    Super (label);
    }

    Protected Sub layout (int width, int height) {}
    int temp = this.getPreferredWidth ();
    setExtent (time, height);
    Super.Layout (time, height);
    }

    }

    resolved http://supportforums.blackberry.com/t5/Java-Development/radiobuttonGroup-related-problem-in-storm/m-...

  • problem in the view of the BitmapFields in HorizontalFieldManager in a line of Blackberry Storm

    I had created a HorizontalFieldManager & BitmapFields said that.

    In Blackberry Storm, Display.getWidth () is 480. I want to use 450 first to add some BitmapFields to LHS of the screen I have create running m & add 2 BitmapFields initially to RHS of the screen.

    2 BimapFields that I want to show initially added to the constructor r & othsr BitmapFields that I m create runtime r added afterwords love...

    class MyCanvas extends MainScreen{
    
    MyCanvas(){
    
    hfm_BitmapField = new HorizontalFieldManager(){            protected void sublayout(int maxWidth, int maxHeight) {                    super.sublayout(maxWidth, maxHeight);                     setExtent(Display.getWidth()-30, 60);                    }         };
    
    startBitmap = Bitmap.getBitmapResource("start.png");        startBitmapField = new BitmapField(startBitmap, BitmapField.ACTION_INVOKE | BitmapField.FIELD_HCENTER | BitmapField.FIELD_RIGHT);hfm_BitmapField.add(startBitmapField);
    
    endBitmap = Bitmap.getBitmapResource("end.png");        endBitmapField = new BitmapField(endBitmap, BitmapField.ACTION_INVOKE | BitmapField.FIELD_HCENTER | BitmapField.FIELD_RIGHT);hfm_BitmapField.add(endBitmapField);
    
    drawBitmap();} 
    
    public void drawBitmap(){
    
    bitmap[i] = new Bitmap(50, 50); Graphics g = new Graphics(bitmap[i]);g.drawLine(5,5,25,25); bitmapField[i] = new BitmapField(bitmap[i]); synchronized(UiApplication.getEventLock()) { hfm.add(bitmapField[i]); }
    
    }
    

    I want startBitmapField & endBitmapField at RHS & bitmapField [i] that I m creating the runtime to LHS of HorizontalFieldManagers.

    I m thinking to add 2 HorizontalFieldManagers. 1 for 1 for startBitmapField & endBitmapField & bitmapField [i]. But how to add 2 HorizontalFieldManagers or any other FieldManagers in a row?

    Any solution? How to do?

    Solved my problem.

  • Focus button HorizontalFieldManager on Storm problem

    I have data exploited these forums looking for a solution but found nothing.  The application I've created has a title bar with 3 fields - previous button, label, next button.  Very simple and the layout works very well.  You cannot set the focus to the right button in the simulator of storm.  You can use the keyboard to navigate to it and click back.  But the keys do not work on this button.  If I change the center field to be a button, it works for the Center button.  Never for the right button.  I think it's a bug, but if you know a whole work please let me know.  Here is the code:

             // create previous button, current label, next button        ButtonField prev = new ButtonField("Prev", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK);        _label = new LabelField("My Label", Field.FIELD_HCENTER);        ButtonField next = new ButtonField("Next", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK);
    
    HorizontalFieldManager header = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH)//HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.NO_HORIZONTAL_SCROLL)//HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.HORIZONTAL_SCROLL | HorizontalFieldManager.HORIZONTAL_SCROLLBAR | HorizontalFieldManager.RIGHTWARD)// | HorizontalFieldManager.NO_HORIZONTAL_SCROLL)
            {
                 public int getPreferredWidth()
                 {
                       return Display.getWidth();
                 }
                 protected void sublayout( int width, int height )
                 {
                    super.sublayout( width, height );
                    width = getWidth();
                    height = getHeight();               
    
                    Field leftField = getField(0);
                    if (leftField != null && equals(leftField.getManager()))
                    {
                        setPositionChild( leftField, 0, 0);
                    }
    
                    Field centerField = getField(1);
                    if (centerField != null && equals(centerField.getManager()))
                    {
                        int w = (width - centerField.getWidth()) / 2;
                        int h = (height - centerField.getHeight()) / 2;
                        setPositionChild( centerField, w, h);
                    }
    
                    Field rightField = getField(2);
                    if (rightField != null && equals(rightField.getManager()))
                    {
                        setPositionChild( rightField, width - rightField.getWidth(), 0);
                    }
                }
            };
            header.add(prev);
            header.add(_label);
            header.add(next);
            setTitle(header);
    

    Solved!

    Basically my manager should not call super, must call layoutChild before positioning and then affecting the scope of the Manager.  Yes, a lot of questions and unfortunately a lot of code examples on this site that.  Please visit this page on the managers how custom must be written:

    http://www.thinkingblackberry.com/archives/74

  • problem with the user interface

    Hello

    I want to store a LabelField and a ButtonField in unique horizontalFieldmanager.

    display aside and left to the right of the label button.

    I was able to view a horizontalField but I want to display as below then how it is possible.

    Text1 button1

    Button2 Text2

    Text3 button3

    Code:

    for (int i = 0; i)<>

    {

    HorizontalFieldManager hfm5 = new HorizontalFieldManager()
    {
    protected void sublayout (int width, int height)
    {
    Field field;
    get the total number of areas falling under this Manager of
    int numberOfFields = getFieldCount();
                   
    System.out.println ("length =" + numberOfFields);
    int x = 0;
    int y = 0;
    for (int i = 0; i)<>
    {
    field = getField (i); get the field
    System.out.println (i + "->" + field);
    setPositionChild(field,x,y);
    layoutChild (field, width, height);
    x += 130;
    }
    setExtent (width, height);
    }
    };

    hfm5. Add (Text);

    hfm5. Add (Button);

    }

    Please help me as soon as possible:

    code above show me data only once.

    example:

    Text1 button1

    Hello

    Thanks for help me.

    I solved problem myself.

  • Custome Field took a nullpointexception in the labefiled and 7.1 paint method only you have this problem! Pls help me?

    KIM I create a custom entry field as below:

    public class AddEditField extends HorizontalFieldManager {
        private LabelField labelField;
        private EditField contentField;
        private RichTextField wrapaddField;
        HorizontalFieldManager textMgr;
        HorizontalFieldManager wrapMgr;
        private static final int HPADDING = Display.getWidth() <= 320 ? 6 : 8;
        Font font;
    
        public AddEditField(String label, Font font, int maxSpace) {
            this(label, 0, font, maxSpace);
        }
    
        public AddEditField(String label, long style, Font cfont, int maxSpace) {
            super(NO_HORIZONTAL_SCROLL);
            this.font = cfont;
            textMgr = new HorizontalFieldManager(HORIZONTAL_SCROLL | FIELD_VCENTER);
            wrapMgr = new HorizontalFieldManager(FIELD_VCENTER);
            wrapaddField = new RichTextField(RichTextField.TEXT_ALIGN_LEFT);
            long cstyle = 0;
            if (style == 0) {
                cstyle = EditField.NO_NEWLINE | EditField.FOCUSABLE
                        | EditField.EDITABLE | FIELD_VCENTER;
            } else {
                cstyle = EditField.NO_NEWLINE | EditField.FOCUSABLE
                        | EditField.EDITABLE | style | FIELD_VCENTER;
            }
            contentField = new EditField(cstyle) {
                protected void paint(Graphics graphics) {
    
                    // Font font = getFont().derive(Font.PLAIN, fontSize);
                    graphics.setFont(font);
                    graphics.setColor(0x666666);
                    super.paint(graphics);
                }
    
                protected void onFocus(int direction) {
                    super.onFocus(direction);
                    invalidate();
                }
    
                protected void onUnfocus() {
                    super.onUnfocus();
                    // if (VirtualKeyboard.isSupported()) {
                    // VirtualKeyboard vKeyboard =getVirtualKeyboard();
                    // vKeyboard.setVisibility(VirtualKeyboard.HIDE);
                    // }
    
                }
            };
            labelField = new LabelField(label, FIELD_LEFT | FIELD_VCENTER) {
                protected void paint(Graphics graphics) {
                    graphics.setColor(0x006699);
                    graphics.setFont(font);
                    super.paint(graphics);
                }
            };
            LabelField spaceF = new LabelField() {
    
                protected void layout(int width, int height) {
                    // TODO Auto-generated method stub
                    //super.layout(HPADDING, font.getHeight() + 10);
                    setExtent(HPADDING, font.getHeight() + 10);
                }
            };
            add(spaceF);
            add(labelField);
            final int space = maxSpace - font.getAdvance(labelField.getText());
            LabelField spaceF2 = new LabelField() {
    
                protected void layout(int width, int height) {
                    // TODO Auto-generated method stub
                    // super.layout(space, font.getHeight() + 10);
                    setExtent(space, font.getHeight() + 10);
                }
            };
            add(spaceF2);
            textMgr.add(contentField);
            wrapMgr.add(wrapaddField);
            add(textMgr);
        }
    
        public String getText() {
            return contentField.getText();
        }
    
        public void setText(String text) {
            synchronized (UiApplication.getEventLock()) {
                wrapaddField.setText(text);
                contentField.setText(text);
            }
        }
    
        public void setEditMode(boolean editable) {
            String text = wrapaddField.getText();
            synchronized (UiApplication.getEventLock()) {
                if (editable) {
                    contentField.setText(text);
                    if (wrapMgr.getManager() == this) {
                        delete(wrapMgr);
                    }
                    if (textMgr.getManager() != this) {
                        add(textMgr);
                    }
                } else {
                    if (textMgr.getManager() == this) {
                        delete(textMgr);
                    }
                    if (wrapMgr.getManager() != this) {
                        add(wrapMgr);
                    }
                }
            }
        }
    
    }
    

    Then I create: new AddEditField ("address:", cFont, maxSpace);  and add it to a screen.

    When I try to open this form. It is nullpointexception: the eclipse debugger show the info such as:

    AddEditField$ 4labelfield.paint line 385.

    Please help me to check the code. why it can run in 0 s 7.0 and before, only 7.1 has had this problem?

    Thank you

    Hi Flybrid,

    I checked at the time of your code,

    I am able to run your code by deleting page layout override methods in two fields of the label.

    The problem with the substitution of the method of layout in the spaceF and spaceF2 fields.

    But I can't explain why.

    I think that you can achieve the same thing by replacing getPrefferedWidth() and getPrefferedHeight() above the fields instead of page layout.

    Thank you.

  • BrowserField encoding problem

    Hello! Please, help me! I spent almost all day, but have had no success. My BrouserField is showing '? ' characters instead of the non-English characters.
    I need to get the Ribbon XML, analyze and display in the BrowserFiled.
    I use these classes:

    (1) WaitScreen - PopupScreen from the example of knowledge base

    public class WaitScreen extends PopupScreen {
    
        private LabelField _ourLabelField = null;
    
        private WaitScreen(String text) {
            super(new HorizontalFieldManager());
            VerticalFieldManager _vfm = new VerticalFieldManager();
            _ourLabelField = new LabelField(text, Field.FIELD_HCENTER);
            _vfm.add(_ourLabelField);
            this.add(_vfm);
            this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 225));
        }
    
        public static void showScreenAndWait(final Runnable runThis, String text) {
            final WaitScreen thisScreen = new WaitScreen(text);
            Thread threadToRun = new Thread() {
                public void run() {
                    // First, Waintdisplay this screen
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            UiApplication.getUiApplication().pushScreen(thisScreen);
                        }
                    });
                    // Now run the code that must be executed in the Background
                    try {
                        runThis.run();
                    } catch (Throwable t) {
                        t.printStackTrace();
                        throw new RuntimeException("Exception detected while waiting: " + t.toString());
                    }
                    // Now dismiss this screen
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            UiApplication.getUiApplication().popScreen(thisScreen);
                        }
                    });
                }
            };
            threadToRun.start();
        }
    }
    

    (2) RSSHandler - class auxiliary for analysis

    public class RSSHandler extends DefaultHandler {
        boolean isItem = false;
    
        boolean isTitle = false;
        boolean isLink = false;
        boolean isDescription = false;
        boolean isPubDate = false;
        boolean isGuid = false;
    
        public String[] title = new String[] {};
        public String[] link = new String[] {};
        public String[] description = new String[] {};
        public String[] pubDate = new String[] {};
        public String[] guid = new String[] {};
        String value = "";
    
        public void startElement(String uri, String localName, String name,
                Attributes attributes) throws SAXException {
            if (!isItem) {
                if (name.equalsIgnoreCase("item"))
                    isItem = true;
            } else {
                if (name.equalsIgnoreCase("title"))
                    isTitle = true;
                if (name.equalsIgnoreCase("link"))
                    isLink = true;
                if (name.equalsIgnoreCase("description"))
                    isDescription = true;
                if (name.equalsIgnoreCase("pubDate"))
                    isPubDate = true;
                if (name.equalsIgnoreCase("guid"))
                    isGuid = true;
            }
        }
    
        public void characters(char[] ch, int start, int length)
                throws SAXException {
            if (isTitle || isLink || isDescription || isPubDate || isGuid)
                value = value.concat(new String(ch, start, length));
        }
    
        public void endElement(String uri, String localName, String name)
                throws SAXException {
            if (isItem && name.equalsIgnoreCase("item"))
                isItem = false;
            if (isTitle && name.equalsIgnoreCase("title")) {
                isTitle = false;
                Arrays.add(title, value);
                value = "";
            }
            if (isLink && name.equalsIgnoreCase("link")) {
                isLink = false;
                Arrays.add(link, value);
                value = "";
            }
            if (isDescription && name.equalsIgnoreCase("description")) {
                isDescription = false;
                Arrays.add(description, value);
                value = "";
            }
            if (isPubDate && name.equalsIgnoreCase("pubDate")) {
                isPubDate = false;
                Arrays.add(pubDate, value);
                value = "";
            }
            if (isGuid && name.equalsIgnoreCase("guid")) {
                isGuid = false;
                Arrays.add(guid, value);
                value = "";
            }
        }
    }
    

    (3) CaptionScreen (screen with BrowserField I need to show the result of the XML parsing)

    public class CaptionScreen extends MyMainScreen
    {
        private BrowserField _browserField;
    
        public CaptionScreen(Application app, String section)
        {
             //....
             GetArticles getArticles = new GetArticles("http://" + _urlWithArticles, _browserField);
             WaitScreen.showScreenAndWait(getArticles, "LOADING");
        }
    
        static class GetArticles implements Runnable {
            String _url = null;
            BrowserField _resultBrowser;
    
            public GetArticles(String urlToGet, BrowserField resultBrowser) {
                this._url = urlToGet;
                this._resultBrowser = resultBrowser;
            }
    
            public void run() {
                // Try to download new articles and parse the answer
                HttpConnection httpConn = null;
                InputStream is = null;
                RSSHandler rssHandler = new RSSHandler();
    
                try {
                    httpConn = GetConnection(_url);
    
                    is = httpConn.openInputStream();
                    try {
                        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                        parser.parse(is, rssHandler);
                    }
                    catch (ParserConfigurationException e) {
                        e.printStackTrace();
                    }
                    catch (SAXException e) {
                        e.printStackTrace();
                    }
                    catch (IOException e) {
                        e.printStackTrace();
                    }
                } catch (IOException ioe) {
                } catch (Exception e) {
                } finally {
                    try {
                        if ( httpConn != null ) {
                            httpConn.close();
                        }
                    } catch (Exception e) {
                    }
                    httpConn = null;
                }
    
                final String htmlArticles = generateHtml(rssHandler);
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        _resultBrowser.displayContent(htmlArticles, "");
                    }
                });
            }        
    
            // Method for html generation to showing in BrowserField
            private String generateHtml(RSSHandler rssHandler) {
                String result = "";
                if(rssHandler == null) {
                    return result;
                }
                result += "News";
    
                for(int i = 0; i < rssHandler.title.length; i++) {
                    result += rssHandler.title[i] + "
    " + "LINK
    " + rssHandler.description[i] + " "; } result += ""; return result; } private HttpConnection GetConnection(String _url) throws IOException { if (DeviceInfo.isSimulator()) { _url = _url + ";deviceSide=true"; } MyConnFact _myConnFact = new MyConnFact(); HttpConnection _httpConn = null; ConnectionDescriptor _connDesc = _myConnFact.getConnection(_url); if (_connDesc != null) { _httpConn = (HttpConnection)_connDesc.getConnection(); } return _httpConn; } } }

    It works very well (showing WaitScreeen, data download), but all characters not English shows as '?'
    I found a few discussions with the same problem (especially this one)

    http://supportforums.BlackBerry.com/T5/Java-development/how-to-show-other-languages-in-BrowserField/...

    and this one

    http://supportforums.BlackBerry.com/T5/Java-development/BrowserField-can-not-display-UTF-8-character...

    but I don't understand, how and where do I I implemented HttpConnection in my code.
    Please, give me advice or tell, how I change my code to solve this problem?

  • horizontalfieldmanager limitation

    I just found out that HorizontalFieldManager can not add more than 1 TextField... When I add 2 TextField in a HorizontalFieldManager and then, I transfer the app to my Blackberry, second TextField will not be displayed. Is there such a restriction for some managers?

    This is not a limitation of the Manager, but a problem of the field, it signals a preferredWidth of unlimited and as a hfm has unlimited width (virtually) it grants this wish.

    You can replace getPreferredWidth on the domain or use a custom layout manager.

  • Button in the pop-up screen problem

    Hi all

    I did a pop-up screen in which there are two buttons and an EditField. Now, I am faced with very weird problem. First button that I added in my code doesnot seem to work. It doesnot clicking and the second button is working well, why is it so can any body help out me of this.

    I provided the code here: -.

    public class PinPopup extends PopupScreen{
    public static  EditField texts;
    static String _userName=null;
    
    PinPopup()
        {
        super(new HorizontalFieldManager());
        Font f = Font.getDefault().derive(Font.BOLD, 16);
        setFont(f);
        texts=new EditField("","",200,Field.EDITABLE);
    
        ButtonField sendButton = new ButtonField(" Send  "){
            protected boolean navigationClick(int status, int time) {
                   Dialog.inform("Send");
                return true;
                }
        };
    
        ButtonField cancelButton = new ButtonField("Cancel"){
             protected boolean navigationClick(int status, int time) {
                   Dialog.inform("Cancel");
                return true;
                }
        };
    
        VerticalFieldManager _fieldManagerContext = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.USE_ALL_HEIGHT)
            {
    
                public void sublayout(int width,int height) {
                    //super.sublayout(width, height);
                    int xpos = 0;
                    int ypos = 0;
                    Field field = getField(0);
                    layoutChild(field, 280, 50);
                    setPositionChild(field, xpos, ypos);
                    Field field1 = getField(1);
                    layoutChild(field1, 280, 50);
                    setPositionChild(field1, xpos+20, ypos+80);
                    Field field2 = getField(2);
                    layoutChild(field2, 280, 50);
                    setPositionChild(field2, xpos+145, ypos+80);
                    setPosition(150, 220);
                    setExtent(300, 220); 
    
                   }
                    public void paint(Graphics graphics)
                    {
                        //graphics.setColor(Color.WHITE);
                        Font f = Font.getDefault().derive(Font.BOLD, 16);
                        graphics.setFont(f);
                        graphics.drawText("SEND PIN",90, 20,0,200);
                        graphics.drawText( _userName,110,40,0,200);
                        graphics.setColor(Color.WHITE);
                        super.paint(graphics);
                    }
    
            }; 
    
                  _fieldManagerContext.add(texts);
                  _fieldManagerContext.add(cancelButton);
                  _fieldManagerContext.add(sendButton);
                  add(_fieldManagerContext);
    
        }
    
    }
    

    Hi Please help me in this

    Thanks in advance

    Why do you not use Horizontalfieldmanager for horizontal alignment.

    This is the code and it works fine.

    package com.winit.mobiads.ui.screens;

    Import net.rim.device.api.ui.Color;
    Import net.rim.device.api.ui.Field;
    Import net.rim.device.api.ui.Font;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.component.ButtonField;
    Import net.rim.device.api.ui.component.Dialog;
    Import net.rim.device.api.ui.component.EditField;
    Import net.rim.device.api.ui.container.HorizontalFieldManager;
    Import net.rim.device.api.ui.container.PopupScreen;

    SerializableAttribute public class PinPopup extends PopupScreen {}
    public static EditField texts;
    public static String _userName = null;

    PinPopup()
    {
    Super (new HorizontalFieldManager());
    Police f = Font.getDefault () .derive (Font.BOLD, 16);
    setFont (f);
    texts = new EditField("","",200,Field.EDITABLE);
           
    ButtonField sendButton = new ButtonField ("send") {}
    protected boolean navigationClick (int status, int time) {}
    Dialog.Inform ("Send");
    Returns true;
    }
    };
         
    ButtonField cancelButton = new ButtonField ("Cancel") {}
    protected boolean navigationClick (int status, int time) {}
    Dialog.Inform ("Cancel");
    Returns true;
    }
    };

    HorizontalFieldManager _fieldManagerContext = new HorizontalFieldManager (USE_ALL_WIDTH)
    {
               
    ' public void sublayout (int width, int height) {}
    Super.sublayout (width, height);
    int xPos = 0;
    int yPos = 0;
    Field = getField (0);
                       
    setPositionChild (field, xpos, ypos);
    layoutChild (field, 280, 50);
                       
    Field Field1 = getField (1);
                       
    setPositionChild (Field1, xpos ypos + 80 + 20);
    layoutChild (Field1, 100, 50);

    Field Field2 = getField (2);
                       
    setPositionChild (Field2, xpos ypos + 80 + 145);
    layoutChild (Field2, 100, 50);
                       
    setPosition (150, 220);
    setExtent (width, height);
                        
    }
    public void paint (Graphics graphics)
    {
    graphics.setColor (Color.WHITE);
    Police f = Font.getDefault () .derive (Font.BOLD, 16);
    graphics.setFont (f);
    graphics.drawText ("SEND PIN", 90, 20,0,200);
    graphics.drawText (_userName, 110, 40, 0, 200);
    graphics.setColor (Color.WHITE);
    Super.Paint (Graphics);
    }
             
    };

    _fieldManagerContext.Add (texts);
    _fieldManagerContext.Add (CancelButton);
    _fieldManagerContext.Add (sendButton);
    Add (_fieldManagerContext);
                     
    }

    }

  • Problem BrowserField2 demo?

    Hello

    I imported BrowserFieldDemo2 of samples of BlackBerry in my eclipse. If I open any website through BrowserField. I may be able to vertically scroll the webpage, but I'm unable to scroll horizontally.

    I want to see the entire Web page.  What may be the problem?

    The browserfield is a VerticalFieldManager, so it must be the width of what it shows, but it can scroll down.

    Put it inside a HorizontalFieldManager and play a little with the style. For me, it works: Field.FOCUSABLE. Manager.VERTICAL_SCROLL | Field.FIELD_HCENTER | Manager.TOPMOST.

Maybe you are looking for