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()!

Tags: BlackBerry Developers

Similar Questions

  • 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 domain is all interactive

    Here is my custom field Manager:

    public class CalendarMenu extends HorizontalFieldManager {
    
        private CalendarButton next_btn;
        private CalendarButton prev_btn;
        private LabelField title;
        private CalendarButtonCallback c;
    
        public CalendarMenu(String monthYear, CalendarButtonCallback c){
            super();
            this.c = c;
    
            Bitmap nextunfocus = Bitmap.getBitmapResource("cal_right_arrow_off_red.png");
            Bitmap nextfocus = Bitmap.getBitmapResource("cal_right_arrow_on_red.png");
            next_btn = new CalendarButton(nextfocus,nextunfocus,1,c);
            add(next_btn);
    
            Bitmap prevunfocus = Bitmap.getBitmapResource("cal_left_arrow_off_red.png");
            Bitmap prevfocus = Bitmap.getBitmapResource("cal_left_arrow_on_red.png");
            prev_btn = new CalendarButton(prevfocus,prevunfocus,0,c);
            add(prev_btn);
    
            /*
            Font titleFont = Font.getDefault().derive(Font.PLAIN,10,Ui.UNITS_pt);
            title = new LabelField(monthYear){
    
                protected void paint(Graphics graphics){
                    graphics.setColor(Color.WHITE);
                    super.paint(graphics);
                }
            };
    
            add(title);*/
    
        }
    
        protected void paintBackground(Graphics graphics){
    
            graphics.setBackgroundColor(Color.BLACK);
            graphics.clear();
        }
    
        protected void sublayout(int maxWidth, int maxHeight){
    
            /*setPositionChild(title,0,0);
            layoutChild(title,40,40);
            */
            setPositionChild(prev_btn,0,0);
            layoutChild(prev_btn,prev_btn.getPreferredWidth(),prev_btn.getPreferredHeight());
    
            setPositionChild(next_btn,200,0);
            layoutChild(next_btn,next_btn.getPreferredWidth(),next_btn.getPreferredHeight());
    
            setExtent(maxWidth,100);
    
        }
    
    }
    

    I was directed to a custom manager of horizontal field to place the title of buttons and the month in my calendar I wanted to, but it appears all the hfm area is clickable, although the buttons I made are 50 x 50. As a test, I emptied everything and just left the sexExtent(maxWidth,100); and even that was clickable and lead to an error. Is this a bug, or should I do my manager differently?

    That was the problem:

    http://supportforums.BlackBerry.com/T5/Java-development/navigationClick-invoked-when-clicking-outsid...

  • Changing custom field problem Listener

    I created a custom field that works as a button. He painted a bitmap to the screen. And when it focuses it changes the color of the image. However, I try to add a field change listener to it. I looked on the forum and found this code.

    protected boolean navigationClick(int status, int time)
    {
         fieldChangeNotify(1);
         return super.navigationClick(status, time);
    }
    

    It works but I have a problem. You see, my button now push a small screen, thin in the stack that has another button of the same type on it (custom button). At the moment it is the only button on this screen, which means that it has the focus. But it seems that once my button has the focus, I can click anywhere and it is always enabled. I only want to be activated when I touch it. Any suggestions? Here is my code

    public class MenuButtonField extends Field
    {
        Bitmap imagePic;
        Bitmap highlightedPic;
        public MenuButtonField(String imageName, String focusedImg)
        {
            super();
            imagePic=Bitmap.getBitmapResource(imageName);
            highlightedPic=Bitmap.getBitmapResource(focusedImg);
        }
    
        public void layout(int width,int height)
        {
            setExtent(20,80);
        }
    
        public boolean isFocusable()
        {
            return true;
        }
    
        public void drawFocus(Graphics graphics, boolean on)
        {
            paint(graphics);
        }
    
        public boolean touchEvent(TouchEvent message)
        {
            int type=0;
            type=message.getEvent();
            if(type==TouchEvent.CLICK)
            {
                fieldChangeNotify(1);
                return true;
            }
            else{
                return false;
            }
        }
    
        protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(1);
            return super.navigationClick(status, time);
        }
    
        protected void paint(Graphics g)
        {
    
            g.drawBitmap(0, 20, 20, 80, imagePic, 0, 0);
    
            if(this.isFocus())
            {
                g.drawBitmap(0, 20, 20, 80, highlightedPic, 0, 0);
            }
    
        }
    }
    

    PLEASE HELP ME

    I found help here
    http://supportforums.BlackBerry.com/T5/Java-development/navigationClick-invoked-when-clicking-outsid...

    The position of Scribe the Lion was the solution.

  • Custom Edit Box Focus / number of character position

    I have a text field within a HorizontalManager (I tried Vertical and Manager as well), but I'm getting a weird problem that it won't navigate left in some and is sail on other screens!

       public CustomEditField(int textcolor,Font font ,int maxchars,long style){
            super(style|Manager.HORIZONTAL_SCROLL);
            color=textcolor;
            bordercolor=TemplateSettings.bordercolor;
            editfield=new EditField(EditField.NO_NEWLINE|style|EditField.FOCUSABLE){
                public void onUnfocus(){
                    System.out.println("Edit Field UnFocus");
                    super.onUnfocus();
                    this.invalidate();
    
                }
    
                public void onFocus(int direction){
                    super.onFocus(direction);
                    this.invalidate();
                }
    
                public void paint(Graphics g)
                {
                    g.setColor(color);
                    super.paint(g);
    
                }
    
                protected void drawFocus(Graphics g,boolean on){
                    XYRect focusRect = new XYRect();
                    getFocusRect( focusRect );
                    int yOffset = 0;
                    if ( isSelecting() )
                    {
                        yOffset = focusRect.height >> 1;
                        focusRect.height = yOffset;
                        focusRect.y += yOffset;
                    }
                    g.pushRegion( focusRect.x, focusRect.y, focusRect.width, focusRect.height, -focusRect.x, -focusRect.y );
                    g.setBackgroundColor( TemplateSettings.focuscolor );
                    g.setColor( 0xFFFFFF );
                    g.clear();
                    this.paint( g );
                    g.popContext();
    
                }
    
            };
    

    He'll just go to the next/previous field instead of changing the position of the character (although sometimes it works ok in one way or the other!, it works very well if the text is more than a line well, someone knows how to bypass?, I tried the substitution of movement of navigation but is not getting hit at the level field or Manager?)

    I have problems with the custom field grid Manager and the navigationmovement in there.

  • Development/unfocus field custom button problem

    Hi all

    I have something weird happens.  I have a custom button field that swaps the images based on a focused state or blur.  I have been using this field custom for awhile now, and I have never had any problems.  Imagine the following provision:

    ______________    ________________________

    | Custom button |    | BasicEditField |

    ------------------------    ------------------------------------------

    When my screen is launched, the focus is on the custom button.  If I move the trackball in a downward movement, the focus is taken the custom button, and its background image changes adequately to what has been defined in the untargeted State.  The BasicEditField then has the focus.  This is the correct behavior.

    If, however, I move the trackball in a movement to the right to the BasicEditField, then the BasicEditField will indeed get the focus, however the custom button field always displays its "highlight" picture  Using print statements, I was able to determine that when I move in a movement to the right with the trackball, the custom field button loses the focus and then gets the focus back to back, that's why it shows the highlighted image.

    Additional info:  This isn't an issue on touch devices, and custom button Manager is a TableLayoutManager.

    Any ideas why this might be happening?  Here's the code to my custom button field:

    public class BitmapButtonField extends Field {
        private String text = "";
        private Bitmap bitmap;
        private Bitmap bitmapHighlight;
        private Bitmap b;
        private boolean highlighted;
    
        public BitmapButtonField(String image, String imageHighlight, long style) {
    
            super(style | Field.FOCUSABLE);
    
            this.bitmap = Bitmap.getBitmapResource(image);
            this.bitmapHighlight = Bitmap.getBitmapResource(imageHighlight);
    
            b = bitmap;
    
        }
    
        public BitmapButtonField(String text, String image, String imageHighlight,
                long style) {
    
            super(style | Field.FOCUSABLE);
    
            this.text = text;
            this.bitmap = Bitmap.getBitmapResource(image);
            this.bitmapHighlight = Bitmap.getBitmapResource(imageHighlight);
    
            b = bitmap;
    
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
            // Do nothing
        }
    
        public int getPreferredHeight() {
            return bitmap.getHeight();
        }
    
        public int getPreferredWidth() {
            return bitmap.getWidth();
        }
    
        protected void layout(int width, int height) {
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
    
        protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(1);
            return true;
        }
    
        protected void onFocus(int direction) {
            b = bitmapHighlight;
            invalidate();
            System.out.println("FOCUSED");
    
        }
    
        protected void onUnfocus() {
            b = bitmap;
            invalidate();
            System.out.println("UNFOCUSED");
        }
    
        protected void paint(Graphics graphics) {
    
            int topTextPadding = (b.getHeight() - getFont().getHeight()) / 2;
            int sideTextPadding = (b.getWidth() - getFont().getAdvance(text)) / 2;
    
            graphics.drawBitmap(0, 0, getWidth(), getHeight(), b, 0, 0);
            graphics.setColor(Color.WHITE);
            if (text.length() > 0) {
                graphics.drawText(text, sideTextPadding, topTextPadding,
                        Graphics.ELLIPSIS, b.getWidth());
            }
        }
    }
    

    Have you looked at navigationMovement in the TableLayoutManager?  I confess that I rewrote it because it handles no left and right as I wanted.  Perhaps, you might be able to do the same thing.

  • Targeted custom HorizontalFieldManager does not click on Storm

    Hello everyone!

    I am facing a problem to make a compatible application to the storm. This application contains some managers of land and within a and that we have a list of custom HorizontalFieldManagers.

    These fields are accept touch and to implement the development, we simply implement the code below:

    protected boolean touchEvent(TouchEvent event){
        switch(event.getEvent()){
        case TouchEvent.DOWN:
            if(!this.focused){
                this.setFocus();
                invalidate();
            }
            break;
        }
        return false;
    }
    

    So, if you click directly on a ground without an accent, it works as expected. But if the field is already concentrated the click does not work! NavigationClick method is not called. In the hand of the command, as shown above, if the field is not well centered the navigationClick is called accordly.

    protected boolean navigationClick(int status, int time) {
        return clickListener.onNavigationBallClicked(this, status, time);
    }
    

    What we need to do to handle that click when the field that is already worn? Or better yet, what we're doing wrong?

    Thank you!!!

    Sorted!

    The trick is below:

    protected boolean touchEvent(TouchEvent event){
        switch(event.getEvent()){
        case TouchEvent.DOWN:
            if(!this.focused){
                this.setFocus();
                invalidate();
            }
            break;
        case TouchEvent.UNCLICK:
               return clickListener.onNavigationBallClicked(this, 0, 0);
        }
        return false;
    }
    
  • Custom step problem

    I have a number of custom steps (not inherited, no source code) that we use with TestStand 3.0 and 3.5 versions.  I'm trying to import them into TestStand 4.1, but I have problems.  I know that the location of the files has changed under TestStand 4.x.  They used to live in the TestStand folder, now they live in C:\Documents and Settings\All Users\Documents\National Instruments\TestStand 4.1\Components.  I copied all the DLLs, INI, ICO, files in the correct folders, but some of the measures do not appear in the context menu when you add a step.  I have added custom, four steps two I have visible, two are not.

    The management mode that Custom steps has changed in the TS 4.1?

    Thank you.

    Have you added your pallets of type under C:\Documents and Settings\All Users\Documents\National Instruments\TestStand 4.1\Components\TypePalettes?

    Your pallets of type and the types of step appear in the Palette of Document Type?

    You may also right-click on the palette to insert a step and choose Customize... to update where your step types appear in the Insert palette.

    Hope this helps,

    -Doug

  • Custom EQ problem

    Hey all,.

    I just got my 8 GB player v2 of detonators and discovered a problem with the custom EQUALIZER setting. The song cut off permanently when being read. It plays fine in all other preset EQ settings (even if it sounds ugly).

    Thanks for any help.

    Make sure that the plug of your headphones is inserted completely into the outlet. They are extremely tight plant. This could be the cause of your problem. Try to twist as you push on it to ensure that it is firmly in place.

  • 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

  • Custom ComboBox problem

    Hello

    I'm doing a custom combobox. I don't want pictures in that text. Inspired by DDImagesButton I coded my Combobox. But am experiencing a few problems with it.

    For the button, I created TextButtonField. Problem that I face this is it shows text only when you click on it once. Otherwise, it shows just background color. Here's the code for TextbuttonField:

    public class TextButtonField extends ButtonField implements FocusChangeListener {
        protected DropdownItem mItem;
        boolean mTextItem;
        int mWidth;
        int mHeight;
        private static final int FOCUS_COLOR_BORDER = Color.RED; //0xFC0000;
        private static final int UNFOCUS_COLOR_BORDER = Color.WHITE;
        private int borderColor = FOCUS_COLOR_BORDER;
        private int color;
        private boolean selected;
    
        public TextButtonField(String text) {
            this(new DropdownItem(null, text), true);
        }
    
        private TextButtonField(DropdownItem item, boolean textItem) {
            super(item.mName, CONSUME_CLICK);
            mItem = item;
            mTextItem = textItem; 
    
            mWidth = (mTextItem ? getFont().getAdvance(mItem.mName) + 6 : 0);
            mHeight = getFont().getAscent() + 6; 
    
            // Save the Width & Height for layout
            mItem.itemWidth = mWidth;
            mItem.itemHeight = mHeight;
    
            setPadding(3, 6, 3, 6);
            setMargin(0, 0, 0, 0);
            this.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
            setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0), Border.STYLE_TRANSPARENT));
            setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0), Border.STYLE_FILLED));
            setFocusListener(this);
        } 
    
        public TextButtonField(String text, int bgColor) {
            this(new DropdownItem(null,text), true);
            this.setBackground(BackgroundFactory.createSolidBackground(bgColor));
        }
    
        protected void paint(Graphics graphics) {
            super.paint(graphics);
        } 
    
        public int getPreferredWidth() {
            return mWidth;
        } 
    
        public int getPreferredHeight() {
            return mHeight;
        } 
    
        protected void layout(int width, int height) {
            setExtent(mWidth, mHeight);
        } 
    
       public void focusChanged(Field field, int eventType) {
            if (eventType == FocusChangeListener.FOCUS_GAINED) {
                borderColor = FOCUS_COLOR_BORDER;
                invalidate();
            }
            if (eventType == FocusChangeListener.FOCUS_LOST) {
                borderColor = UNFOCUS_COLOR_BORDER;
                invalidate();
            }
        }
    
        protected void drawFocus(Graphics g, boolean on) {
            paint(g);
        }
    }
    

    By using this class, I created the ComboBox class such as:

    public class ComboBox extends TextButtonField implements FieldChangeListener {
        DropdownItem[] mItems;
        int mIndex;
        boolean showSelectedText;
        private int maxTextInd =0;
    
        public ComboBox(DropdownItem items[]) {
            super(items[0].mName);
            mItems = items;
            updateIndex(0);
            setChangeListener(this);
        }
    
        public ComboBox(DropdownItem items[], int bgColor) {
            super(items[0].mName, bgColor);
            mItems = items;
            updateIndex(0);
            setChangeListener(this);
        }
    
        protected void paint(Graphics graphics) {
            super.paint(graphics); 
    
            int x = 0;
            int ht =  0;
            x = this.getFont().getAdvance(mItems[maxTextInd].mName) + 5;
    
            int y = 5; 
    
            int y1 = y;
            int y2 = y + 10;
            int x1 = x;
            int x2 = x + 18;
            int[] xPts = new int[] { x1, x2, x1 + 9 };
            int[] yPts = new int[] { y1, y1, y2 };
            graphics.drawFilledPath(xPts, yPts, null, null);
        } 
    
        public void fieldChanged(Field f, int context) {
            getScreen().getUiEngine().pushScreen(new ComboPopUp());
        }
    
        public void updateIndex(int index) {
            mIndex = index;
            mItem = mItems[mIndex];
            invalidate();
        }
    
        public int getSelectedIndex() {
            return mIndex;
        }
        public String getSelectedItem() {
            return mItems[mIndex].mName;
        }
    
        class ComboPopUp extends PopupScreen implements FieldChangeListener {
            public ComboPopUp() {
                super(new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR));
                for (int i = 0; i < mItems.length; i++) {
                    TextButtonField button = new TextButtonField(mItems[i].mName);
                    add(button);
                    button.setChangeListener(this);
                }
                getField(mIndex).setFocus();
            } 
    
            protected boolean keyChar(char key, int status, int time) {
                if (Keypad.KEY_ESCAPE == key) {
                    this.close();
                    return true;
                } else
                    return super.keyChar(key, status, time);
            } 
    
            public void fieldChanged(Field field, int context) {
                updateIndex(getFieldWithFocusIndex());
                this.close();
            }
        }
    }
    

    * Here if the index is changed, I want to see the ot the button of the selected index. I want to say that if I have 2 items in the drop-down list 'Save' & 'Edit', Save is 1 then it will be displayed, if I select "Edit" then change must be considered over the top and not save. This time is seen as st element.

    * In DDImagesButton, next to the button, the triangle is hsown, which indicates a drop down, here how can I show that. In DDImagesButton, I have not found where and what show this triangle.

    * The popup is displayed correctly, but the text is not displayed until the component is selected. This issue will be resolved when TextButtonField problem is solved.

    Although these 2 problems are a little different but as relate to them, I added in the same message.

    Can you help me to solve my problems and help me create the custom drop-down list box. Help is highly appreciated.

    Thank you

    Hi Piotr,

    Consideirng your instructions, I tried to implement and make changes accordingly, but nothing has worked... I knew that both the setBorder is necessary. For ascent, creaed a label with alphabet 'W' and I am for his ascension.

    By developing, I realized the problem and resolved completely. In fact, I've been putting the text of the TextButtonField in super(), I removed that and displays text in object. It also helped me view the drop-down arrow that was not coming. I changed the following code and little bit here & there, and things were as expected.

    private TextButtonField(DropdownItem item, boolean textItem) {
            super(CONSUME_CLICK);
            ..........
     }
    
        protected void paint(Graphics graphics) {
            super.paint(graphics);
            graphics.setColor(Color.WHITE);
            graphics.setFont(textFont);
            graphics.drawText(mItem.mName, XPad, 1);
        }
    

    The drop down menu is not visible completely because of the size of the layout. Changed the width of TextButtonField in ComboBox object after showing the arrow that is:

    totWidth = x 2;

    and layout() TextButtonField:

    Protected Sub layout (int width, int height) {}
    setExtent (Math.max (mWidth, totWidth), mHeight);
    }

    That's all, and my work is done. Above code is added with explanation so can serve to someone else like me.

    Thank you

  • Custom InputPopup: Problem Unclickable button

    For some reason, the 'ok' button is disabled. Cancel button and modify the field very well work.

    package Misc.Screens;
    
    import Thread.InputRunnable;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.FontFamily;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Ui;
    import net.rim.device.api.ui.XYEdges;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.EditField;
    
    import net.rim.device.api.ui.container.PopupScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    import net.rim.device.api.ui.decor.BorderFactory;
    
    public class InputPopup extends PopupScreen implements FieldChangeListener {
    
        private Font def;
        private ButtonField ok = new ButtonField("Yes", ButtonField.CONSUME_CLICK
                | ButtonField.FOCUSABLE);
        private ButtonField cancel = new ButtonField("Cancel",
                ButtonField.CONSUME_CLICK);
        private InputRunnable runme;
        private static final int VPADDING = 5;
        private static final int TVPADDING = 10;
        private EditField input = new EditField() {
            protected void paint(Graphics graphics) {
                graphics.setColor(Color.BLACK);
                super.paint(graphics);
            }
        };
    
        public InputPopup(InputRunnable runme) {
            super(new VerticalFieldManager() {
                protected void sublayout(int width, int height) {
                    // TODO Auto-generated method stub
                    if (getFieldCount() > 2) {
    
                        Field f1 = getField(0);
                        Field f2 = getField(1);
                        Field f3 = getField(2);
                        layoutChild(f1, width, height);
                        layoutChild(f2, width, height);
                        layoutChild(f3, width, height);
    
                        setPositionChild(f1, (width - f1.getWidth()) >> 1, VPADDING);
                        setPositionChild(f2, ((width / 3)) - (f2.getWidth() >> 1),
                                f1.getHeight() + TVPADDING);
                        setPositionChild(f3, ((width / 3) << 1)
                                - (f3.getWidth() >> 1), f1.getHeight() + TVPADDING);
                        setExtent(width, f1.getHeight() + f2.getHeight()
                                + TVPADDING);
                    }
    
                }
            });
    
            this.runme = runme;
            FontFamily theFam;
            try {
                theFam = FontFamily.forName("BBAlpha Sans");
                def = theFam.getFont(Font.PLAIN, 8, Ui.UNITS_pt);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            setBackground(BackgroundFactory.createLinearGradientBackground(
                    0x0099CCFF, 0x0099CCFF, 0x00336699, 0x00336699));
            setBorder(BorderFactory.createBitmapBorder(new XYEdges(12, 12, 12, 12),
                    Bitmap.getBitmapResource("image.png")));
    
            input.setBorder(BorderFactory.createBitmapBorder(new XYEdges(12, 12,
                    12, 12), Bitmap.getBitmapResource("image.png")));
            input.setBackground(BackgroundFactory
                    .createSolidBackground(Color.WHITE));
            input.setFont(def);
    
            ok.setFont(def);
            ok.setChangeListener(this);
    
            cancel.setFont(def);
            cancel.setChangeListener(this);
            add(input);
    
            add(ok);
            add(cancel);
    
        }
    
        public String getString() {
            return input.getText();
        }
    
        public void fieldChanged(Field field, int context) {
            if (field.equals(ok)) {
                runme.setInput(getString());
                runme.run();
                input = null;
                ok = null;
                cancel = null;
                close();
            } else {
                input = null;
                ok = null;
                cancel = null;
                close();
            }
    
        }
    
    }
    

    This has been tested on the Simulator and the device. The 'ok' button gets focus on a device with a trackpad or trackball. However, on the touch phones the 'ok' button will not focus.

    Fix a problem:

    Instead of using a VerticalFieldManager, I just used a plain old Manager and acquired button concentrated.

  • visibility of custom dialog problem

    Hello

    I used a dialog box custom in my project to a pop up. I used the tutorial of the custom dialog box. Depending on whether, when the dialog box appears, the back groundpage will be inactive and when the dialog box is closed, which becomes active. My question is, when I click on the 'OK' button in the dialog box, the background page is not turned in the first press itself. It seems that, after awhile, the inactive background color became more dark or black color, and I need to continue to press the ok button in the dialog box several times to close the box.

    No idea how to get rid of this?

    It's the happening bcz every time when you go to the third page, the signal connects again and again. If you need to cut the signal back to the third page. This is how you handle this

    paneProperties: {NavigationPaneProperties}
    ButtonBack: {ActionItem}
    onTriggered: {}
    myApp.mySignal.disconnect (showPrompt)
    yourNavPaneId.pop ();
    }
    }
    }

    Place this code in your page 3, and I hope this will solve your problem.

    Please like this if you are answered.

  • Custom ButtonField Field.FOCUSABLE + Field.FIELD_HCENTER

    I am doing a custom button class that can change the color of the button when it is concentrated AND make it Central on the screen, I can make one of these but not both.

    This is the constructor for the class CustomButtonField

       public CustomButtonField(String text){
            super(Field.FOCUSABLE);
            this.text = text;
            //this.highlightColour = 0x18333C;
            FontFamily fFam = null;
            try {
                fFam = FontFamily.forName("Arial");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
                    Font font = fFam.getFont(Font.PLAIN, 20);
            Font defaultFont = font;
            fieldHeight = defaultFont.getHeight() + padding;
            fieldWidth = defaultFont.getAdvance(text) + (padding * 2);
            this.setPadding(2, 2, 2, 2);
    
        }
    

    Evolution:

    Super (Field.FOCUSABLE)

    TO

    Super (Field.FIELD_HCENTER)

    allows me to do the other, but not both at the same time, all clues?

    Thank you!

    Super(Field.FOCUSABLE |) Field.FIELD_HCENTER);

  • Paint custom button problem

    Hi, I have a custom button that must be next to a labelfield.

    The paint of the button code is:

     protected void paint(Graphics graphics) {
    
       graphics.drawBitmap(13, 0, fieldWidth, fieldHeight, button, 0, 0,);
    
    }
    

    Where '13' is the space between labelfield and button. But when the font size is larger, the result is the following: [IMG]http://i34.tinypic.com/xeq2hu.jpg[line]

    The button is cut off and other times, its even more. What could be a solution?

    Thanks in advance.

    A HorizontalFieldManager defines the fields from left to right, it only wraps to the next line.  You can use a FlowFieldManager to achieve that has the fields from left to right, then on the next line below.

Maybe you are looking for

  • With regard to the Tempro alerts

    Hello I noticed that there are multiple alerts for the same programs, such as facial recognition and Tempro, and I was wondering these alerts must be downloaded in order, or can I just try to download the most anterior and ignore the rest? Thank you

  • Digital output frequency seems to be twice the frequency generated by the basic function generator

    Hi Labview forum, I wrote a program (attached) Labview to generate 3 PWM, square wave, signals that has the same frequency and phase delay right (so that when a signal is off, the other signal is lit. Then the next signal). Everything seems to work f

  • Work in photographs in itself

    I use a Lenovo Thinkpad X 301... then I put my work in Photo to its library arranged in a single ffolders file consist of about thirty to forty photos so I put 15 to 20 records in each library (more or less) now I can't start or do something this por

  • Extension file mode FPGA or 9802

    Hi all I would like to know if it is possible to change the file extensions of the files created with the NOR-9802 using the FPGA. I see that they are saved as BIN but is there the chance that it could be. TXT or. CSV so that they are easily accessib

  • Vista SP2 x 64 install failed with error 80004005

    I tried to install the SP2 for Vista X 64 (KB948465) four times.  The most recent installation attempt failed after(1) created a new administrator account and did the following...(2) uninstalled CA Antivirus Suite (no other antivirus installed).(3) s