CheckboxField [] and fieldChangeListener.

Hello

I need a dynamic number of checkboxes for a project I'm working on. My code example is as follows. Somehow, I get an jvm stackoverflow exception.

public class abc() extends screen implements {FieldChangeListener}

CheckboxField [] boxField;

public abc() {}

.

.

.

the length is variable.

boxField = new CheckboxField [length];

VFM VerticalFieldManager = new VerticalFieldManager();

for (int i = 0; i)

boxField [i] = new CheckboxField();

boxField [i] .setChangeListener (this);

VFM. Add (boxField [i]);

}

Add (VFM);

}

Sub fieldChanged (field field, int context) {}

Hardcode for now. The intention is to loop through and uncheck all

except one who was just ticked.

chkBoxField [0] .setChecked (false); StackOverflow exception

}

}

Help?

In this way:

chkBoxField [0] .setChecked (false);

You set the value of the checkbox, prompting to advise its FieldChangeListener, which is to set the value of the box, which advises the FieldChangeListener... I could go on.   Until what I stack overflowed of course.

Although there are many ways to stop this, I think that you should be aware of using the context provided to the fieldChanged method.  To check

FieldChangeListener.PROGRAMMATIC

If it matches, then the change was made by a program and not by the user, in which case you should ignore the change.

For example:

Sub fieldChanged (field field, int context) {}

If (context == FieldChangeListener.PROGRAMMATIC) {}

Only to process user changes to checkboxes

return;

}

.....

Hope it makes sense.

Edit: this has been creating during the validation of RexDoug, my apologies for the repetition.

Tags: BlackBerry Developers

Similar Questions

  • ObjectChoiceField and FieldChangeListener

    I'm creating an application (Storm 9530 component package 4.7) that uses an ObjectChoiceField which is filled by anywhere from 1 to 50 choice programming.  I would use the FieldChangeListener to generate a new pop-up screen based on the selection made by the user of the ObjectChoiceField.  Because the list can be quite long, the user may need to scroll the list to find their choice.  Each time the selection is changed in the FieldChangedListener is called, but I want only to take action in the final selection is made ("clicked").  I have been in charge of the search and search but have not found the key to understand the current state of the ObjectChoiceField (open or closed).  Any help would be greatly appreciated.

    TIA,

    Tim

    You will not be able to differentiate between these types of changes within a FieldChangeListener.  Instead, you might have the user selects an entry and use a ButtonField or MenuItem to check their choice.  Or you could have your action occur when the focus is moved out of the ObjectChoiceField.

  • TouchEvent event and FieldChangeListener aid management

    I have a class screen that extends screen and implements FieldChangeListener. I have a function that captures

    TouchEvent.

    protected boolean touchEvent(TouchEvent te)

    I also have a function as implents FieldChangeListener

    ' Public Sub fieldChanged (field field, int context)

    I get all the touchevents in the touchEvent function, but once I did information there, I need to go to the normal processing, is there a way to implements this? or at least goto the function fieldChanged with the right parameters (scope, context)

    While when I click on an event, it goes to fieldChanged. I use picture.setChangeListener (this) to the fields I

    Thank you

    event management methods return true if the event has been consumed or handled and false otherwise.
    If you want the event to wander in the chain must return false in your implementation of tocuhEvent (I don't know if the touch events are addressed later)

  • CheckboxField, on the same line with OS6

    Hello

    I'm testing my apps for compatibility with OS6.  I discovered that if I have more controls, and then another on the same line, behavior went from OS5.  The first control's display while the other controls are moved outside of the screen.  Any idea on how to solve this problem while keeping compatibility?  Here's the code I'm referring to:

    HorizontalFieldManager hfmOperator = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
    
    int intRightSpace = Display.getWidth()/10;
    
    LabelField lblOperator = new LabelField("");
    lblOperator.setFont(Font.getDefault().derive(Font.PLAIN, 18));
    lblOperator.setPadding(0, intRightSpace, 0, 0);
    hfmOperator.add(lblOperator);
    
    chkADD = new CheckboxField("+",  Param.boolActiveADD);
    chkADD.setFont(Font.getDefault().derive(Font.PLAIN, 24));
    chkADD.setPadding(0, intRightSpace, 0, 0);
    hfmOperator.add(chkADD);
    
    chkSUB = new CheckboxField("-",  Param.boolActiveSUB);
    chkSUB.setFont(Font.getDefault().derive(Font.PLAIN, 24));
    chkSUB.setPadding(0, intRightSpace, 0, 0);
    hfmOperator.add(chkSUB);
    
    chkMUL = new CheckboxField("*",  Param.boolActiveMUL);
    chkMUL.setFont(Font.getDefault().derive(Font.PLAIN, 24));
    chkMUL.setPadding(0, intRightSpace, 0, 0);
    hfmOperator.add(chkMUL);
    
    chkDIV = new CheckboxField("/",  Param.boolActiveDIV);
    chkDIV.setFont(Font.getDefault().derive(Font.PLAIN, 24));
    chkDIV.setPadding(0, intRightSpace, 0, 0);
    hfmOperator.add(chkDIV);
    
    add(hfmOperator);
    

    The only way I could get to this day is to override the method of layout in the CheckboxField and spend a fixed width to the super method:

    protected void layout(int width, int height) {
        super.layout(100, height);
    }
    

    The problem with this approach is that the width of the content can vary from a device to according to the size of font by default, etc. and it may be possible to try to force a specific width.

  • Increase in the size of the boxes

    Hello..

    I am adding instances of checkboxfield and adding them to the vertical field Manager. I want to increase the size of the boxes. How can I do?

    Please suggest.

    Thanx.

    must override layout() field box to increase the size.

    Here is the code snippet

    public void layout (int width, int height)
    {
    Super.Layout (width, height);
    setExtent (200, 300); specify your width and height for check box field
    }

  • Help: fieldChanged is not implemented

    Hello

    Please help me on this bug.

    I'm working on BB Storm2 9520, developing on JRE 5.0.0 not JRE (API) 6.0.0

    I created a class BaseScreen, which extends the screen and implements FieldChangeListener

    public abstract class BaseScreen extends MainScreen implements FieldChangeListener{    protected MToolbarButtonField btn1;    protected MToolbarButtonField btn2;    protected MToolbarButtonField btn3;    protected MToolbarButtonField btn4;    protected MToolbarButtonField btn5;    protected ToolbarManager toolbarManager;
    
        public BaseScreen() {        toolbarManager = new ToolbarManager();        HorizontalFieldManager hfm = new HorizontalFieldManager();        hfm.add(btn1);        hfm.add(btn2);        hfm.add(btn3);        hfm.add(btn4);        hfm.add(btn5);        toolbarManager.add(hfm);        setStatus(toolbarManager);    }
    
        public void fieldChanged(Field field, int context)     {        System.out.println("======== Toolbar Button Clicled ========");    }
    
    }
    

    Class MToolbarButtonField extends the ToolbarButtonField class:

    public class MToolbarButtonField extends ToolbarButtonField{    private Bitmap bmpIcon;
    
        public MToolbarButtonField(Bitmap bmp) {        super(Field.FOCUSABLE, bmp);        bmpIcon = bmp;    }
    
        protected void paint(Graphics g) {        //...    }}
    

    Class ToolbarButtonField extends the class of field:

    public class ToolbarButtonField extends Field{    private Bitmap bmpIcon;
    
        public ToolbarButtonField(long style, Bitmap bmp) {        super(style);        bmpIcon = bmp;    }
    
        protected void paint(Graphics g) {        //...    }
    
        protected boolean navigationClick(int status, int time)     {        fieldChangeNotify(1);        return true;    }
    
    }
    

    Then, I created some screens that extends the BaseScreen class and FieldChangeListener tools:

    public class Screen1 extends BaseScreen implements FieldChangeListener{    private BitmapButtonField btn1;    private BitmapButtonField btn2;
    
        public Screen1() {        btn1 = new          BitmapButtonField(Bitmap.getBitmapResource(               "bntmyinfos.png"),              Field.FOCUSABLE| FIELD_LEFT | FIELD_VCENTER);        btn2 = new BitmapButtonField(Bitmap.getBitmapResource(              "bntmycont.png"),              Field.FOCUSABLE| FIELD_LEFT | FIELD_VCENTER);    }
    
        public void fieldChanged(Field field, int context) {        System.out.println("==== Screen1 buttons clicked");        //...    }}
    

    When I clicked on the btn1, btn2 on Screen1, the Screen1.fieldChanged prints to the Console Windows "= Screen1 buttons clicked.

    But when I clicked the btn1 on toolbar, nothing happenned.

    I've already put the style buttons toolbarManager are FOCUSABLE so why nothing is there?

    What should I do to make the BaseScreen.fieldChanged took place?

    Everyone please help.

    Thanks in advance.

    Hi guys,.

    Thank you for your support.

    Now, I already solved the problem.

    And the solution is the fieldChangeNotify (int context) method.

    Add this method in the ToolbarButtonField class, and it works.

    Here is my code that worked:

    ToolbarButtonField

    public class ToolbarButtonField extends Field (    private Bitmap bmpIcon;
    
        public ToolbarButtonField(Bitmap bmp)    {        super(Field.FOCUSABLE);        bmpIcon = bmp;    }
    
        protected void fieldChangeNotify(int context) {           this.getChangeListener().fieldChanged(this, context);       }
    
        protected boolean navigationClick(int status, int time)     {        fieldChangeNotify(1);        return true;    }
    
        protected void paint(Graphics g)    {        //...    }    //...}
    

    and some changes: in BaseScreen, let the fieldChanged method do nothing, change the MToolbarButtonField of extends from ToolbarButtonField to implements FieldChangeListener, and then implement the fieldChanged here method:

    public class MToolbarButtonField implements FieldChangeListener {
        private Bitmap bmpIcon;
        private BaseScreen caller
        private ToolbarButtonField btn1;
        private ToolbarButtonField btn2;
        private ToolbarButtonField btn3;
        private ToolbarButtonField btn4;
        private ToolbarButtonField btn5;
        private VerticalFieldManager toolbarFieldManager;
    
        public MToolbarButtonField(BaseScreen caller) {
            this.caller = caller;
            toolbarFieldManager = new VerticalFieldManager();
    
            btn1 = new ToolbarButtonField();
            btn1.setChangeListener(this);
            btn2 = new ToolbarButtonField();
            btn2.setChangeListener(this);
            btn3 = new ToolbarButtonField();
            btn3.setChangeListener(this);
            btn4 = new ToolbarButtonField();
            btn4.setChangeListener(this);
            btn5 = new ToolbarButtonField();
            btn5.setChangeListener(this);
    
            toolbarFieldManager.add(btn1);
            toolbarFieldManager.add(btn2);
            toolbarFieldManager.add(btn3);
            toolbarFieldManager.add(btn4);
            toolbarFieldManager.add(btn5);
        }
    
        public void addToolbarToScreen()
        {
            caller.setStatus(toolbarFieldManager);
        }
    
        public void fieldChanged(Field field, int context)
        {
            if (field == btn1)
            {
                System.out.println("Button 1 clicked !");
            }
            if (field == btn2)
            {
                System.out.println("Button 2 clicked !");
            }
            if (field == btn3)
            {
                System.out.println("Button 3 clicked !");
            }
            if (field == btn4)
            {
                System.out.println("Button 4 clicked !");
            }
            if (field == btn5)
            {
                System.out.println("Button 5 clicked !");
            }
        }
    }
    

    BaseScreen:

    public abstract class BaseScreen extends MainScreen implements FieldChangeListener
    {
        MToolbar toolbarManager;
        /**
         * Creates a new MyScreen object
         */
        public BaseScreen()
        {
            // Set the displayed title of the screen
            setTitle("Toolbar Button display");
    
            toolbarManager = new MToolbar(this);
            toolbarManager.addToolbarToScreen();
        }
    }
    

    MyScreen (Screen1 last time):

    public class MyScreen extends BaseScreen {
        private ButtonField btn6;
        private ButtonField btn7;
    
        VerticalFieldManager vfm;
    
        public MyScreen()
        {
        vfm = new VerticalFieldManager();
        btn6 = new ButtonField("MyScr button 1", Field.FOCUSABLE);
        btn6.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int content)
            {
            Dialog.alert("My Screen's button 1 clicked!");
            }
        });
        vfm.add(btn6);
    
        btn7 = new ButtonField("MyScr button 2", Field.FOCUSABLE);
        btn7.setChangeListener(new FieldChangeListener()
        {
            public void fieldChanged(Field field, int content)
            {
            Dialog.alert("My Screen's button 2 clicked!");
            }
        });
        vfm.add(btn7);
    
        this.add(vfm);
        }
    }
    
  • Prevent screen scrolling

    Hello everyone

    I now objects on the screen:

    1. the VerticalFieldManager that contains 1 ButtonField and 1 SeparatorField, after that

    2. I have VerticalFieldManager that contains a list of variables CheckboxFields and 1 SeparatorField, after that

    3. I HorizontalFieldManager that contains 3 buttons.

    Each time the list of the CheckboxField is longer than the 3rd screen HorizontalFieldManager of the screen shuts off and cannot be seen until what I scroll.

    When I scroll the 1 VerticalFieldManager scrolls upward.

    Y at - it a way to keep the VerticalFieldManager 1st and 3rd HorizontalFieldManagers are still visible in 2nd scroll VeriticalFieldManager scrollable?

    Thank you

    Hi DD12,.

    I have a screen almost the same as you wish.

    Change my screen a bit more like yours.

    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.system.*;
    
    public class TestScreen extends MainScreen
    {
    
        private VerticalFieldManager topManager;
        private VerticalFieldManager middleManager;
        private HorizontalFieldManager bottomManager;
    
        public TestScreen()
        {
    
            super(NO_VERTICAL_SCROLL);
    
            topManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL);
            topManager.add(new ButtonField("Button1"));
            topManager.add(new SeparatorField());
    
            int btnWidth = (Display.getWidth() / 3) - 2 ;
            bottomManager= new HorizontalFieldManager();
            bottomManager.add(new FixedWidthButtonField("Button2",btnWidth));
            bottomManager.add(new FixedWidthButtonField("Button3",btnWidth));
            bottomManager.add(new FixedWidthButtonField("Button4",btnWidth));
    
            middleManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
            {
                /*
                public void paint(Graphics graphics)
                {
                    graphics.setBackgroundColor(0x00000000);
                    graphics.clear();
                    super.paint(graphics);
                }
                */
                protected void sublayout( int maxWidth, int maxHeight )
                {
                    int displayWidth = Display.getWidth();
                    int displayHeight = Display.getHeight() - (topManager.getPreferredHeight() + bottomManager.getPreferredHeight());
    
                    super.sublayout( displayWidth, displayHeight);
                    setExtent( displayWidth, displayHeight);
                }
            };
    
            // add your dynamic contents to the middleManager
            middleManager.add(new SeparatorField());
    
            this.add(topManager);
            this.add(middleManager);
            this.add(bottomManager);
        }
    
        class FixedWidthButtonField extends ButtonField
        {
            private int width;
    
            FixedWidthButtonField( String label, int Width)
            {
                super( label);
                width = Width;
            }
    
            public int getPreferredWidth(){
                return width;
            }
        }
    }
    

    Hope this will help you.

    Concerning

    Bika

  • Problem With nested Manager in DialogFieldManager

    I display successfully a PopupScreen with an icon, title, two fields of line and two buttons to the right places.  I do this by calling the constructor of PopupScreen with DialogFieldManager

    The problem is fixed height BasicEditField as I am trying to add.  There is space for the BasicEditField, but the BasicEditField is not.

    Here is the code I use.  Note: I left the ButtonField and FieldChangeListener code to stay brief.  I also tried to use customManager.add () instead of delegateFieldManager.addCustomField ()... or work:

         eflink = new EditField("", link);
            efname = new EditField("", "");
            befd = new BasicEditField("", "")
            {
                public int getPreferredHeight()
                {
                    return 60;
                }
            };
            dsm = dfm.getCustomManager();
            hfm = new HorizontalFieldManager(Manager.FIELD_HCENTER);
            tvfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL)
            {
                protected void sublayout( int maxWidth, int maxHeight )
                {
                    int width = maxWidth;
                    int height = maxHeight;
                    width = dfm.getWidth();
                    height = dfm.getHeight() + befd.getPreferredHeight();
                    // super.sublayout( width, height);
                    setExtent( width, height);
                }
            };
            dfm.addCustomField(eflink);
            dfm.addCustomField(efname);
            //
            tvfm.add(befd);
            hfm.add(post);
            hfm.add(cancel);
            dfm.addCustomField(tvfm);
            dfm.addCustomField(hfm);
         }
    

    Can you see what I'm doing wrong?

    Solved!

    I took the code of this doc, deleted the reference EditField and adding a field to the constructor parameter.

    I then used the custom manager that results in place of the VerticalFieldManager in my previous code... using the fixed EditField as the field to the Manager constructor arg custom.

  • EditField and checkboxfield on the same line

    public CheckFileScreen()
        {
            vfm = new VerticalFieldManager();
            left = new HorizontalFieldManager( Field.FIELD_LEFT);
            right = new HorizontalFieldManager( Field.FIELD_RIGHT);
            _Id = new EditField("Id : ", "", 6, EditField.FILTER_NUMERIC);
            _check = new CheckboxField("check", false);
                    left.add(_Id);
            right.add(_check);
            vfm.add(left);
            vfm.add(right);
            add(vfm);
            add(new SeparatorField());
        }
    

    on my above code tries to _id and _check on the same line, but the screen has been mess up

    +---------------

    | ID:

    | # check

    +----------------

    I want to create has been

    +----------------------

    | ID: # check

    +-----------------------

    could someone help me with this?

    This is the first time make app with GUI

    Gentlemen.

    slow down, please!

    Absolutely, totally useless any Manager available personalized for that! In order to organize two or more fields in a 'line', you just all of them to the same HorizontalFieldManager! The manager then places them from left to right in the order that you add them.

    That said - you have a slight problem in your EditField. EditField is "width-hungry" - it consumes the entire width, it is given, do not leave anything for the rest fields. To combat that, to deceive him into thinking he's got less space. We will give him what he needs to label 6 larger figures (s '8' or '9's, not '1') and a space for the padding. We will then have something like:

    _Id = new EditField("Id : ", "", 6, EditField.FILTER_NUMERIC) {
      protected void layout(int width, int height) {
        Font myFont = getFont();
        int myWidth = myFont.getAdvance(getLabel()) + myFont.getAdvance("8") * 6 + myFont.getAdvance(" ");
        super.layout(Math.min(myWidth, width), height);
      }
    };
    _check = new CheckboxField("check", false);
    HorizontalFieldManager hfm = new HorizontalFieldManager();
    hfm.add(_Id);
    hfm.add(_check);
    add(hfm);
    

    Enjoy!

  • FieldChangeListener on a ButtonField displays a prompt with named Application Switch and full Menu options dialog box. instead of the action set.

    Hi I use a ButtonField in my class of the screen and adds a ChangeListener and provided the measures required in

    fieldChanged(Field field, int context)
    

    method. But everytime that I click on a button, a dialog box invites you to two play as Application Switch options and full Menu.


    I think that there is a method that must be overridden to avoid this problem. I get this result when I run my app in the device with OS 5.0, but it works fine on the Simulator (7.0).

    Use ButtonField.CONSUME_CLICK as a style.

    your override of navigationclick should also work, but you would raise the event changed yourself field before return true.

  • How do I know what checkboxfield is changed?

    How do I know when the checkboxfield (value true or false) is changed by the user?

    I want to receive event when the user changes the status of the checkboxfield.

    For example,.

    Sub UserChangedCheckboxfield()

    {

    Dialog.Alert ("you change the State of the checkbox");

    }

    Create a FieldChangeLIstener and attach it to the box field.

  • My native BB app, how to connect to the remote URL and call a Web service method to retrieve the XML base result using Eclipse Version 3.7.2

    Hello

    I am new to the development of native applications from BB using JDE. I'm testing Simulator. From my native BB app, I connect a remote URL and call a Web service method to extract some basic result XML.

    I need to write a login code remote URL to achieve? If so, how?

    So, how can I use this connection object to call the Web service from this URL remotely.

    Please help me out of it...

    Many thanks in advance...

    What i am doing is, On clicking the "Login" button i want to call the webservice method like below mentioned code...
    Here WaveServices is a class and getAllCinemas() is a static method inside which a webservice method call is made..
    
    loginButtonField.setChangeListener(new FieldChangeListener() {
                public void fieldChanged(Field paramField, int paramInt) {
                    WaveServices.getAllCinemas();
                }
            });
    

    Indeed, the question was raised and answered here:

    http://supportforums.BlackBerry.com/T5/Java-development/from-my-native-BB-application-how-to-connect...

  • TouchEvent & FieldChangeListener both does not work

    Hello

    I have 2 bitmapfields and a buttonfield. I want that all fields to intercept the click event. Initially, I had added only fieldChangeListeners to all fields, but bitmap field has not answered them (despite making them Focusable). I added touchevent to handle events click for all areas, now all fields respond only touchEvents. Same buttonfield does not meet fieldChange that he met before adding the touchEvent.

    Can someone help me to know the problem and the solution for the same. I want that all fields to react to events through contact or normal by a click. Also in touchEvent as navigationClick added id, if the menu is not coming, but otherwise with the other menu click only just who should not and the fieldchangelistener should be handled.  Here's the code.

        private BitmapField  signOffBtn, profileBtn;
        private ButtonField btn;
    
        public LoggedUserScreen(UserBean user) {
            super();
            this.loggedUser = user;
            System.out.println("Into LoggedUserScreen : Got user");
            init();
            this.add(signOffBtn);
            this.add(profileBtn);
            this.add(btn);
        }
    
        private void init() {
            signOffBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE ) {
                protected boolean navigationClick(int status, int time) {
                    return true;    // handle click event
                }
            };
            profileBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE ) {
                protected boolean navigationClick(int status, int time) {
                    return true;    // handle click event
                }
            };
            btn = new ButtonField("button", BitmapField.HIGHLIGHT_SELECT |  BitmapField.FOCUSABLE);
            signOffBtn.setChangeListener(this);
            profileBtn.setChangeListener(this);
            btn.setChangeListener(this);
        }
    
        public void fieldChanged(Field field, int context) {
            if (field == signOffBtn) {
                System.out.println("********* SIGN OFF CLICKED");
            } else if (field == profileBtn) {
                System.out.println("********* PROFILE CLICKED");
            } else if (field == btn) {
                System.out.println("********* button CLICKED");
                System.exit(0);
            }
        }
    
       public int getFieldAtLocation(int x, int y)    {
             XYRect rect = new XYRect();
             int index = getFieldCount() -1;
             while (index >= 0)        {
                getField(index).getExtent(rect);
                if (rect.contains(x, y))
                    break;
                 --index;
             }
             return index;
      }
    
      protected boolean touchEvent(TouchEvent event) {
    
          switch(event.getEvent()) {
              case TouchEvent.DOWN:
                return true;
              case TouchEvent.MOVE:
                return true;
              case TouchEvent.UP:
                return true;
              case TouchEvent.CLICK:
                int index = getFieldAtLocation(event.getX(1), event.getY(1));
                // Ignore click events outside any fields
                if (index == -1)
                    return true;
    
                Field field = getField(index);
                if (field == signOffBtn) {
                    System.out.println("Touched SignOff");
                } else if (field == profileBtn) {
                    System.out.println("Touched Profile");
                } else if (field == btn) {
                    System.out.println("Touched Button");
                }
                return true;
          }
          return false;
      }
    

    Thank you

    Ago I already watched this about such removeFocus or setFocus (false) or more. But yes, your something.setFocus gave me the idea to setFocus on the screen itself for the development is removed from the key also and not on any component capable of intercepting the event.

    So if I add fieldChangeNotify (0); in signOffBtn navigationclick, profileBtn & btn, then I totally don't need to implement the touchEvent?

        private void init() {
            signOffBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE | ButtonField.FIELD_LEFT) {
                protected boolean navigationClick(int status, int time) {
                    fieldChangeNotify(0);
                    return super.navigationClick(status, time);    // handle click event
                }
            };
            profileBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE | ButtonField.FIELD_RIGHT ) {
                protected boolean navigationClick(int status, int time) {
                    fieldChangeNotify(0);
                    return super.navigationClick(status, time);    // handle click event
                }
            };
            imageBtn = new ImageButton(Bitmap.getBitmapResource("icon.png"), Bitmap.getBitmapResource("icon.png"));
            btn = new ButtonField("button", BitmapField.HIGHLIGHT_SELECT |  BitmapField.FOCUSABLE | ButtonField.FIELD_RIGHT) {
                protected boolean navigationClick(int status, int time) {
                    fieldChangeNotify(0);
                    return super.navigationClick(status, time);    // handle click event
                }
            };
    
            signOffBtn.setChangeListener(this);
            profileBtn.setChangeListener(this);
            imageBtn.setChangeListener(this);
            btn.setChangeListener(this);
        }
    

    touchEvent is totally deleted & navigationClick is implemented for each button.

    Thank you. I just want to confirm, with this, my componetns everything will work for touch & non touch screen properly. 9530 Simulator touch screen reacts (left mouse click), but not touch that is a click (muose right clisk) does not do anything. So I was wondering...

  • Problem with pop and pushScreen

    Hello everyone.

    I recently started to create an app for BlackBerry, so I'm still pretty new at this... I am having trouble with the anti-pop and pushScreen. I searched a lot but many solutions I find do not work for me. Essentially, here's what I want to do, when we click on a button, the screen must be closed (exploded view) and it must come to the screen I want that there. Here is the code im using with screen names and everything:

            ButtonField button = new ButtonField("Click!", ButtonField.CONSUME_CLICK);
    
            button.setChangeListener(new FieldChangeListener() {
    
            public void fieldChanged(Field field, int context) {
            UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());;
            UiApplication.getUiApplication().pushScreen(new LyricLordInfo());
            }
            });
    
            add(button);
    

    I want to switch from the current screen which is called 'LyricLordMainScreen' to the screen called "LyricLordInfo". I created a class to display "LyricLordInfo".

    But when I use this code, it is not to the next screen, instead it seems basically that just, it refreshes the current screen because the screen just highlights one buttons up and don't go to the screen, I wanted to.

    Any ideas on what could be the problem?

    Thank you!

    your LyricLordInfo screen seems a bit strange.
    LyricLordMainScreen extension will be very probably do not have what you want so that you do not use the super constructor that it would create.

    and why it does not contain main method? makes no sense.

    for reasons of this issue, I would say that you extend screen with LyricLordInfo.

  • FieldChangeListener for the custom field does not...

    Hi all

    I searched for him and almost all positions tried but failed to get the solution of it. Here is my code. My problem is when I click on the individual images the fieldchangelistener must be called and the message.

    package com.samples;
    
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    public class CustomPaintingScreen extends MainScreen implements FieldChangeListener
    {
        CustomClass[] custom;
    
        FieldChangeListener itemlistener = new FieldChangeListener() {
    
            public void fieldChanged(Field field, int context)
            {
                Dialog.alert("clicked");
            }
        };
    
        public CustomPaintingScreen()
        {
            setTitle("Custom Painting ");
            custom = new CustomClass[10];
            VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLLBAR|Manager.LEAVE_BLANK_SPACE);  
    
            for (int i = 0; i < custom.length; i++)
            {
                custom[i] = new CustomClass();
                custom[i].setChangeListener(itemlistener);
                vfm.add(custom[i]);
            }
            this.add(vfm);
        }
    
        public void fieldChanged(Field field, int context)
        {
            if(field instanceof CustomClass)
            {
                Dialog.alert("clicked");
            }
        }
    }
    

    and here's my customclass

    package com.samples;
    
    import java.util.Vector;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    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.XYRect;
    
    public class CustomClass extends Field //implements FieldChangeListener
    {
        private XYRect dest;
        private Bitmap bitmap;
        private Vector vtr;
        private Bitmap next;
    
        public CustomClass()
        {
            bitmap = Bitmap.getBitmapResource("laptop.png");
            next = Bitmap.getBitmapResource("next.png");
            dest = new XYRect(20,15,bitmap.getWidth(),bitmap.getHeight());
            //this.setChangeListener(this);     
    
            vtr = new Vector();
        }
    
        protected void layout(int width, int height)
        {
            height = getFont().getHeight()* 5;
            setExtent(Display.getWidth(), height);
        }
    
        protected void paint(Graphics graphics)
        {
            graphics.setColor(0xFF7F24);
            graphics.fillRoundRect(5, 5, (getWidth()-10), (getFont().getHeight()*5), 30, 40);
            graphics.drawBitmap(dest, bitmap, 0, 0);
            graphics.setColor(Color.BLACK);
            int x = bitmap.getWidth()+25;
            int y = 15;
            graphics.setFont(getFont().derive(Font.BOLD));
            graphics.drawText("Dell Laptop", x, y, 0, getWidth());
            graphics.setFont(getFont().derive(Font.PLAIN,15));
    
            String str= "Discover Dell Inspiron and XPS Laptops with advanced technology.this is dell laptop";
            vtr = wrap(str, 300,graphics);
            System.out.println(" "+vtr.toString());
    
            graphics.drawBitmap(335, 15, next.getWidth(), next.getHeight(), next, 0, 0);
    
    //      graphics.drawText(vtr.toString(), x, (y+20), 0,300 );
        }
    
        private Vector wrap (String text, int width,Graphics graphics)
        {
            int x = bitmap.getWidth()+25;
            int y = 35;
    
            Vector result = new Vector ();
            if (text == null)
               return result;
    
            boolean hasMore = true;
    
            // The current index of the cursor
            int current = 0;
    
            // The next line break index
            int lineBreak = -1;
    
            // The space after line break
            int nextSpace = -1;
    
            while (hasMore)
            {
               //Find the line break
               while (true)
               {
                   lineBreak = nextSpace;
                   if (lineBreak == text.length() - 1)
                   {
                       // We have reached the last line
                       hasMore = false;
                       break;
                   }
                   else
                   {
                       nextSpace = text.indexOf(' ', lineBreak+1);
                       if (nextSpace == -1)
                          nextSpace = text.length() -1;
                       int linewidth = this.getFont().getAdvance(text,current, nextSpace-current);
                       // If too long, break out of the find loop
                       if (linewidth > width)
                          break;
                   }
              }
              String line = text.substring(current, lineBreak + 1);
    
              graphics.drawText(line, x, y, 0,350 );
              y=y+15;
    
              result.addElement(line);
              result.addElement(new String("\n"));
              current = lineBreak + 1;
         }
         return result;
        }
    
        protected boolean navigationClick(int status, int time)
        {
            fieldChangeNotify(1);
            return super.navigationClick(status, time);
        }
    
        protected void fieldChangeNotify(int context)
        {
            super.fieldChangeNotify(context);
        }
    }
    

    also my images look like this

    When I click on the individual images, the dialog box should appear. I tried a lot of things. give me a code. for screen touch for example jde4.7 and jde4.5

    Hi peter - what did I want to add the listener on the image above and manipulate. and the picture above, I created using the graphics object. so this is the question that I am able to get the listener?

Maybe you are looking for