EditField length...

Hello

How can I set the maximum length of an editfield?

Check this constructor of EditField. You can set Max Number of "charas".

EditField (Label style Asstring , String initialValue, maxNumChars int, long)
Built a smaller object of EditField tagged content original and distinctive style.

Tags: BlackBerry Developers

Similar Questions

  • EditField listener to check the length of the field

    I have a phone field which is an editfield.

    I could restrict entry to 10 digits in this field to hold mobile digital values.

    But now I want to add an additional post that throws an error dialogue once the user typed a value less than 10 in this area.

    This action must be triggered as soon as the user has typed something and went to the next field.

    Here is my code:

    LabelField lbl1 = new LabelField(" Phone No:            ");
    
           final EditField TextField2 = new EditField("", "", 10, 0)
           {
              //Some statements
           }
    
    TextField2.setChangeListener(new FieldChangeListener()
            {
              public void fieldChanged(Field field, int context)
              {
                  if(TextField2.getText().length() < 10)
                              System.out.println("Please enter a valid 10 digit mobile number!");
              }
            });
    

    Help, please. Thank you.

    As @simon_hain said, let me quote myself: "you must override the onUnFocus method.

    protected void onUnfocus(){  if(getText() == null || getText().length() < 10)    Dialog.alert("Text too short!");}
    
  • Custom elegant EditField (textbox)

    Hello!

    I was wondering if there is a way to create cute user interface components for our applications. I would like to have something like this:

    But the EditField BB is very very ugly. I tried a custom EditField of (http://www.blackberryforums.com/developer-forum/218757-custom-text-edit-filed-vertical-scroll.html)

    But it looks like this:

    It's completely is and ugly, not decent for any application. For cute, we should override the paint method and draw a Bitmap simulating a cute EditField?

    public void paint(Graphics g) {
        super.paint(g);
        g.drawBitmap(0, 0,50, 50, Bitmap.getBitmapResource("profile.png"), 10, 10);
        //g.drawRect(0, 0, getWidth(), getHeight());
    }
    

    If we paint a Bitmap with the height and width fixed, we will see it very small or big if the resolution is changed? For example, in "BOLD" curve with 320 x 240 or 480 x 360.

    Thank you!

    First of all - there is no built-in component like the one you want.

    Second - the article you mentioned has a very harmful code that would avoid you best. I don't know what drunk monkey for the first time getManager () .invalidate () inside the paint, but this piece of code has found its place in more than one article of the BlackBerry UI on the ' Net. Avoid it like the plague.

    Third - you need paint Bitmap image first, then call the super.paint. Otherwise, your bitmap image is painted on the letters!

    Fourth - indeed, the image will be different on different screens. There is a drawTexturedPath method that allows all sorts of affine transformations and the tiles of the original Bitmap. It is quite effective, but could distort Bitmaps. There is also the drawShadedFilledPath, which creates a sort of background gradient. Finally, there are all sorts of classes useful net.rim.device.api.ui.decor package (available since 4.6).

    And finally, the answer to your first question - Yes, there are several ways to create cute user interface components. Here's the complete code for my experience with rounded edge text boxes (it fate multi-line, scrollable vertically)-you can experiment with colors and other things there.

    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FocusChangeListener;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.EditField;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    public  class RoundBorderTextBoxField extends Manager implements FocusChangeListener {
        private int managerWidth;
        private int managerHeight;
        private int inactiveBorderColor = Color.BLACK;
        private int activeBorderColor = Color.BLACK;
        private int borderColor = inactiveBorderColor;
        private int backgroundColor = Color.WHITE;
        private int arcWidth;
    
        private VerticalFieldManager vfm = new VerticalScrollManager(VERTICAL_SCROLL | USE_ALL_WIDTH | USE_ALL_HEIGHT);
        private EditField editField;
    
        RoundBorderTextBoxField(int width, int height, long style) {
            super(style | NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
            managerWidth = width;
            managerHeight = height;
            long innerStyle = style & (READONLY | FOCUSABLE_MASK); // at least
            if (innerStyle == 0) {
                innerStyle = FOCUSABLE;
            }
            editField = new EditField("", "", EditField.DEFAULT_MAXCHARS, innerStyle);
            editField.setFocusListener(this);
            arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE; // make it even
    
            add(vfm);
            vfm.add(editField);
        }
    
        public void setFont(Font font) {
            super.setFont(font);
            editField.setFont(font);
            arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE;
            updateLayout();
        }
    
        public void setBorderColors(int inactive, int active) {
            inactiveBorderColor = inactive;
            activeBorderColor = active;
            invalidate();
        }
    
        public void setBackgroundColor(int bgColor) {
            backgroundColor = bgColor;
            invalidate();
        }
    
        RoundBorderTextBoxField(int width, int height) {
            this(width, height, 0L);
        }
    
        public String getText() {
            return editField.getText();
        }
    
        public void setText(String newText) {
            editField.setText(newText);
        }
    
        public void append(String addedText) {
            String newText = editField.getText() + addedText;
            editField.setText(newText);
            editField.setCursorPosition(newText.length());
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    vfm.setVerticalScroll(Math.max(0, vfm.getVirtualHeight() - vfm.getVisibleHeight()));
                }
            });
        }
    
        public int getPreferredWidth() {
            return managerWidth;
        }
    
        public int getPreferredHeight() {
            return managerHeight;
        }
    
        protected void sublayout(int w, int h) {
            if (managerWidth == 0) {
                managerWidth = w;
            }
            if (managerHeight == 0) {
                managerHeight = h;
            }
            int actWidth = Math.min(managerWidth, w);
            int actHeight = Math.min(managerHeight, h);
            layoutChild(vfm, actWidth - arcWidth, actHeight - arcWidth); // Leave room for border
            setPositionChild(vfm, arcWidth / 2, arcWidth / 2);  // again, careful not to stomp over the border
            setExtent(actWidth, actHeight);
        }
    
        protected void paint(Graphics g) {
            int prevColor = g.getColor();
            int myWidth = getWidth();
            int myHeight = getHeight();
            g.setColor(backgroundColor);
            g.fillRoundRect(0, 0, myWidth, myHeight, arcWidth, arcWidth);
            g.setColor(borderColor);
            boolean aaLines = g.isDrawingStyleSet(Graphics.DRAWSTYLE_AAPOLYGONS);
            g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true);
            g.drawRoundRect(0, 0, myWidth, myHeight, arcWidth, arcWidth);
            g.drawRoundRect(1, 1, myWidth - 2, myHeight - 2, arcWidth - 2, arcWidth - 2);
            g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, aaLines);
            g.setColor(prevColor);
            super.paint(g);
        }
    
        public void focusChanged(Field field, int eventType) {
            if (field == editField) {
                switch (eventType) {
                case FOCUS_GAINED:
                case FOCUS_LOST:
                    adjustBorderColor();
                    break;
                default:
                    break;
                }
            }
        }
    
        private void adjustBorderColor() {
            int nextColor;
            if (editField.isFocus()) {
                nextColor = activeBorderColor;
            } else {
                nextColor = inactiveBorderColor;
            }
            if (borderColor != nextColor) {
                borderColor = nextColor;
                invalidate();
            }
        }
    }
    
  • Impose fixed length validation

    I have an editfield to contain the entered PHONE number.

    I would like to have a fixed length of 10 numbers (not more or less) entry

    How can I achieve this?

    This is my code for phone editfield:

    //Add box next to field for containing input
           HorizontalFieldManager hfm1 = new HorizontalFieldManager();
           LabelField lbl1 = new LabelField(" Phone No:            ",10);
    //Adding 10 here doesnt help
    
           final EditField TextField2 = new EditField()
           {
               boolean _drawFocus = false;
                protected void layout(int maxWidth, int maxHeight)
                {
                    super.layout(Math.min(maxWidth, 300), Math.min(maxHeight, 20));
                }
              protected boolean keyChar(char ch, int status, int time)
                    {
                    if (CharacterUtilities.isDigit(ch) || (ch == Characters.BACKSPACE))
                    {
                    return super.keyChar(ch, status, time);
                    }
                   return true;
                    }
    }
     };
           TextField2.setBorder(BorderFactory.createRoundedBorder(new XYEdges(2,2,2,2)));
           hfm1.add(lbl1);
           hfm1.add(TextField2);
           add(hfm1);
    

    Please guide. Thank you

    If you don't want an initial value, you can use it like this:

    final EditField TextField2 = new EditField(yourLabel, "", 10, 0); //0 means no style.
    

    And, if you want to use your label separately:

    final EditField TextField2 = new EditField("", "", 10, 0); //0 means no style.
    

    E.

  • Cursor/Caret appearing does not in EditField?

    I have an EditField which cursor/insertion sign does not appear.  What Miss me?  Here is my code (and I use 4.5.0 and SIM 8300):

    myEditField = new EditField( "", "", 7, Field.EDITABLE | Field.FIELD_LEFT ){
    
    // inner class method to set field size (setExtent)
    public void layout( int width, int height ) {
      int maxFontWidth = getFont().getAdvance( "W" );
      int fieldSize = myEditField.getMaxSize();
      int newWidth = maxFontWidth * fieldSize;
      setExtent( newWidth, getPreferredHeight() );
    }
    
    // inner class methods to handle changes onFocus/onUnfocus
    public void onFocus( int direction ) {
      super.onFocus( direction );
      invalidate();
    }
    
    public void onUnfocus() {
      super.onUnfocus();
      invalidate();
    }
    
    // inner class method to set text/background colors
    public void paint( Graphics g ) {
      if (myEditField.isFocus()) {
        g.setBackgroundColor( Color.LIGHTGREY );
      } else {
        g.setBackgroundColor( Color.WHITE );
      }
      g.fillRect( 0, 0, getWidth(), getHeight() );
      g.setColor( Color.NAVY );
      g.clear();
      g.drawText( myEditField.getText(), 0, 0 );
      super.paint( g );
    }
    
    }; // end inner class overrides
    

    Try this.  Sorry do not know what I changed to your code at random is went through she change things that did not look right.  However, the 'trick' is the drawFocus.

    In any case, I need to real work, please review, compare, test etc and see how you go.

    myEditField = new EditField( "Label", "Text", 7, Field.EDITABLE | Field.FIELD_LEFT ){
    
      boolean _drawFocus = false;
    
    // inner class method to set field size (setExtent)
    public void layout( int width, int height ) {
      int maxFontWidth = getFont().getAdvance( "W" );
      int fieldSize = this.getMaxSize() + this.getLabel().length();
      int newWidth = maxFontWidth * fieldSize;
      super.layout( newWidth, height );
    }
    
    // inner class methods to handle changes onFocus/onUnfocus
    protected void onFocus( int direction ) {
      super.onFocus( direction );
      invalidate();
    }
    
    protected void onUnfocus() {
      super.onUnfocus();
      invalidate();
    }
    
    protected void drawFocus(Graphics graphics,
                             boolean on) {
      _drawFocus = on;
      super.drawFocus(graphics, on);
      _drawFocus = false;
    }
    
    // inner class method to set text/background colors
    public void paint( Graphics g ) {
      if ( _drawFocus ) {
        super.paint(g);
        return;
      }
      int currCol = g.getColor();
      if (this.isFocus()) {
        g.setBackgroundColor( Color.LIGHTGREY );
      } else {
        g.setBackgroundColor( Color.WHITE );
      }
      g.fillRect( 0, 0, getWidth(), getHeight() );
      g.clear();
      g.setColor( Color.NAVY );
      super.paint( g );
      g.setColor(currCol);
    }
    
    }; // end inner class overrides
    
  • How together/moving Focus automatically to the next editfield?

    Hello

    I'm working on an application I need four editfield a key field, in these I put the setMaxSize 4, it works very well...

    Now, I want when user enter these editfield four letters the update automatically move to the next field.

    Please provide any reference code or logic.

    Thanks in advance.

    I would like to start by adding the editfields to their own data structure (a vector, for example), makes it easier to access.

    You can crush keyChar on the editfield and check the length of the text, if it is the maximum length call you setFocus on the next editfield (as appropriate).

  • EditField with button on a single line

    Hello

    How can I put a text field and a button on the same line field?

    Is there a way to recover the image of contacts to use as a bitmap on the button field?

    How is it possible that it is not a component already built for an edit field phone number with key contacts on the side?

    Another question: is it possible, on the same line, add a horizontally centered label, and a button left-aligned?

    Thank you

    an editfield uses the width full-screen by default. You can change this by substituting getPreferredWidth or by using a custom layout.

    Yes. I use this code:

    if (blackberryContact.countValues(BlackBerryContact.PHOTO) > 0) {
      byte[] photoEncoded = blackberryContact.getBinary(BlackBerryContact.PHOTO, 0);
      byte[] decodedPicture = Base64InputStream.decode(photoEncoded, 0, photoEncoded.length)
    }
    

    I guess that the field is not commonly used and can be developed easily.

    Yes, with a custom presentation: http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

  • EditField unresponsive

    Hi all

    Have a problem when I add an EditField, BasicEditField or an AutoTextEditField. I need to hold the button down to get no response even in this case the entrance is all uppercase.

    See you soon

    VerticalFieldManager searchVFM = new VerticalFieldManager (Manager.FIELD_HCENTER |) Manager.FIELD_VCENTER);
    final AutoTextEditField SearchText = new AutoTextEditField();
    searchVFM.add (SearchText);
    ButtonField SubmitSearch = new ButtonField("Search");
    final submitButtonListener SubmitSearchListener = new submitButtonListener() {}
    ' Public Sub fieldChanged (field field, int context) {}
    If (SearchText.getText () .length)< 3)="">
    Dialog.ask (Dialog.D_OK, "Enter Search must be at least 3 characters");
    }
    }
    };
    SubmitSearch.setChangeListener (SubmitSearchListener);
    searchVFM.add (SubmitSearch);
    Add (searchVFM);

    The substitution of these methods to provide personalized key behaviour.  If you want to use the default behavior, they should not be substituted or must call super.keyChar/keyDown, if you do.

  • How to use EditField?

    Hello

    I want to input the editField aid or any input field, but to filter the characters. As I want to let anly *, +, 0-9, no other displayed if entered... How do I implements it... Need help

    I hope that code below will help you.

    {} public boolean keyChar (key char, int status, int time)
                   
    String c ="";
    int len = txtBox.getText () .length ();
    if(Key==net.) RIM. Device.API.System.Characters.Enter)
    {
    Return super.keyChar (key, status, time);
    }
    Another yew (key is net .rim .device are .characters .ESCAPE .api)
    {
    Return super.keyChar (key, status, time);
    }
    Another yew (key is net .rim .device .api are .characters .BACKSPACE)
    {
    Return super.keyChar (key, status, time);
    }
    if(Len>-1)
    {
    c = txtBox.GetText ();
    If ((Len) == 0)
    {
    If (((int) Key > 126) |) (((int) key > 38) & ((int) key))<>
    {
    Returns false;
    }
    on the other
    {
    If ((clé (int)! = 91) & ((int) key! = 93) & ((int) key! = 96) & ((int) key! = 92) & ((int) key! = 124) & ((int) key! = 36) & ((int) key! = 60) & ((int) key! = 123) & ((int) key! = 171) & ((int) key! = 177) & ((int) key! = 187) & ((int) key! = 62) & ((int) key! = 125) & ((int) key! = 126) & ((int) key! = 94) & ((int) key! = 61) & ((int) key! = 247))
    {
    Return super.keyChar (key, status, time);
    }
    on the other
    {
    Returns false;
    }
    }
    }
    on the other
    {
    If (((int) Key > 126))
    {
    Returns false;
                                   
    }
    on the other
    {
    If ((clé (int)! = 91) & ((int) key! = 93) & ((int) key! = 36) & ((int) key! = 92) & ((int) key! = 96) & ((int) key! = 124) & ((int) key! = 60) & ((int) key! = 123) & ((int) key! = 171) & ((int) key! = 177) & ((int) key! = 187) & ((int) key! = 62) & ((int) key! = 125) & ((int) key! = 126) & ((int) key! = 94) & ((int) key! = 61) & ((int) key! = 247))
    {
    Return super.keyChar (key, status, time);
    }
    on the other
    {
    Returns false;
    }
    }
    }
                       
    }
    on the other
    {
    Return super.keyChar (key, status, time);
    }
    }
    };

  • EditField.getText returns ""?

    Hi, on a PopupScreen,

    2 buttons (OK, CANCEL), 3 editFields (username, etc.), each button has a setChangeListener,.

    but when earphone OK button is called, username.getText () returns «»

    What is the problem on the code?

    Thank you-

    Code:

    LabelField infoStatus = new LabelField();
        EditField username = new EditField("username:", "", 10, EditField.EDITABLE);
        EmailAddressEditField email = new EmailAddressEditField("email: ","", 255, EmailAddressEditField.EDITABLE);
        PasswordEditField password = new PasswordEditField("password: ","", 10, PasswordEditField.EDITABLE);
    
        public NewUserForm()
        {
            super();
    
            LabelField infoStatus = new LabelField();
            EditField username = new EditField("username: ", "", 10, EditField.EDITABLE);
            EmailAddressEditField email = new EmailAddressEditField("email: ","", 255, EmailAddressEditField.EDITABLE);
            EditField password = new EditField("password: ","", 10, PasswordEditField.EDITABLE);
    
            ButtonField bOK = new ButtonField();
            bOK.setLabel("OK");
            bOK.setChangeListener(new NewUserFormOKListener());
    
            ButtonField bCANCEL = new ButtonField();
            bCANCEL.setLabel("CANCEL");
            bCANCEL.setChangeListener(new NewUserFormCANCELListener());
    
            HorizontalFieldManager hfm = new HorizontalFieldManager();
            hfm.add(bOK);
            hfm.add(bCANCEL);
    
            VerticalFieldManager vfm = new VerticalFieldManager();
            vfm.add(infoStatus);
            infoStatus.setText("Complete form and press OK.", 0, -1);
    
            vfm.add(username);
            vfm.add(email);
            vfm.add(password);
            vfm.add(hfm);
    
            add(vfm);
        }
    
        public void CloseNewUserForm() {
            Ui.getUiEngine().popScreen(this);
        }
    
        protected class NewUserFormOKListener implements FieldChangeListener{
            public void fieldChanged(Field field, int context) {
                GPSDeviceResult result = null;
               if (ValidateForm()){
                //TODO.                                 }
               }else
                 Ui.getUiEngine().pushGlobalScreen(new MessagePopup("All fields are mandatory."),1, UiApplication.GLOBAL_MODAL);
            }
    
        }
    
    private boolean ValidateForm(){
            if ((username.getText().trim().length() == 0) || (email.getText().trim().length() == 0) || (password.getText().trim().length() == 0))
                return false;
            else
                return true;
        }
    

    make the global user name field.  Parade outside

    NewUserForm()
    

    .

  • Do white EditFields


    Not 100% sure you understand this:

    "And there is no label before either."

    I presume you are saying that white includes the label.  That is right.  The field includes the Label and the text.  The code I provided takes the entire field and makes the white background.  So, which includes the label.

    There are two ways to solve this problem:

    (a) use a HorizontalFieldManager, add the label ' as a separate LabelField, then add the EditField with no "label".

    (b) have the code as the beginning of the paint box after the label.  You can calculate where that is using code such as

    textX = this.getFont () .getAdvance (this.getLabel ());

    However, this method fails if you go on 1 line - try it and see!

    Re

    "The white box extends the length of the screen."

    What is too long.  BasicEditField, by default takes the entire width.  You must override the layout to change that.  Search the Forum, this was asked before.

    I deliberately say not everything here because then you learn to do things like this for yourself.  Sorry, just the way I do things.

  • How to set the width in EditField

    I have my customEditField, and I put my 40 width and height using (Font.getHeight), to calculate the height. I set the max characters no. 3 when I enter 3 characters in the EditField, I see 3 characters I typed in editfield in simulaors as Pearl curve, but I couldn't see all the 3 characters in 8900, I see 2 characters only, so how do I set the width of my editField

    How can I do this?

    (i) if I have the same width, how can incase I do horizontal scrolling in my edit field

    (II) without using the scroll option, how can I determine my editfield based on my characters length maximum width (i currently use only 3 characters to type here and I need its respective width).

    Concerning

    Rakesh Shankar.p

    Agree with Stephen, here is a code which may help

    int this.getFont ().getAdvance("000") = width;

  • Swimming pool series 2 pool length QUESTION

    When I try to start a pool swim, why are my pool length options 0-x yards vs say:

    -vgs 25

    -25 m

    -50 m

    It's ridiculous and if I want to swim in an Olympic pool, how can I ensure training will be recording with precision (laps, distance, same HR)?

    so far, not good with series 2 for fitness addicts. It seems that this watch (like the latter) too focused on activity monitoring for older and/or shape (rings) people and is not good for people who are in need of fitness Garmin-esque data.

    You do not discuss Apple here. This is a user to user support forum, Apple does not participate.

    If you have Apple to know how you feel about this issue, then click on the link back here, http://www.apple.com/feedback and click on the box in this area.

  • shorten the length of the midi region

    How to change the length of a MIDI region without losing all the notes in the passage? I'm looking to ask recorded solo MIDI on an audio recording. By dragging the end or at the beginning of the region of MIDI to change its length eliminates some notes. I need to keep the whole region by making he puts in time on the audio MIDI. Thank you for any assistance.

    Press and hold the option key down while you drag the lower edge of the region when developing or compress midi.

  • How can I increase the max message length?

    Tried to send an approx. 300 Mbps video via Thunderbird, but got the message that themail exceeded the length of 2000000.

    300 Mbps? Or maybe even 300 MB? By e-mail?

    Are you serious?

    Many e-mail servers have limits such as 10 or 20 MB per message. Some users do not even have 300 MB mailboxes.

    What is the exact wording of the message? I think it's a server, not Thunderbird.

    Do you have Thunderbird not invite you to use the box or similar? Have you tried dropbox or YouSendIt services type?

Maybe you are looking for