Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified
Accepted Solution

Prompt/hint/place holder text on a Numeric/Password edit field

Hi all,

I am trying to introduce prompt text/hints for the edit fields in my application. I capture the key pressed in the keyChar() api and accordingly

 

  • show hint text if the edit field is empty 
  • hide already displayed hint text when the first character is entered
This works for an edit field with filter type DEFAULT.
However I am unable to achieve the same for an edit field with type NUMERIC or for a PasswordEditField. Any ideas on how this can be achieved ? 
Any help will be highly appreciated.
Thanks.

 

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Prompt/hint/place holder text on a Numeric/Password edit field

you can use a textfilter in your input method (keychar etc) without setting it to the field. this allows you to write a string into a field, but the user can only enter numbers, for example.

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: Prompt/hint/place holder text on a Numeric/Password edit field

Can you please elaborate on the idea.

 

What i make out from your response is that I use the DEFAULT filter on the edit text, and from the keyChar() , i block the user from entering anything but numbers.

 

However doing this will display the alpha-numeric keyboard only, whereas i want to restrict the keyboard to numeric type.

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Prompt/hint/place holder text on a Numeric/Password edit field

yes, you are right.

what you could do would be replace the editfield as soon as it is focused.

this means the hint-text is only available while the field is not focused, of course.

 

another option would be to use a tooltip or an overlay (no api for this).

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: Prompt/hint/place holder text on a Numeric/Password edit field

Thanks for clarifying,

This is what i have done : 

 

  1. Construct the edit field with DEFAULT filter type, set the hint/prompt text as its initial value and display the field.
  2. On the keyDown() , if the current text is same as the hint/prompt text then clear the text,set the filter to NUMERIC and set text as the current entered character.
  3. Since the character is entered from the alpha-numeric keyboard, and displayed on a numeric field, the character is converted to a junk numeric value and displayed, which i want to avoid.
  4. I follow a similar strategy for showing the hint/prompt text when there the text inside the field is empty.
I already tried to show/hide the hint/prompt text on focus/unfocus events and it works fine even with changing the filter.
However, what I am trying to achieve is a functionality similar to Android' editText which has a setHint() on it.The hint text disappears only when a character is entered into it, rather than when it is focussed.

 

Please use plain text.
Developer
Eugen
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Prompt/hint/place holder text on a Numeric/Password edit field

Nice hint. Mark your post as solution.

 

However to be perfect it should also display "numeric" input indicator when user focuses the field. I don't know any API to do that.

 

You can play with AbsoluteFieldManager - display some unfocusable LabelField under EditField and remove it when user starts typing. Wierd!

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Prompt/hint/place holder text on a Numeric/Password edit field

I think one way to do this is to paint your hint directly onto the EditField.  That way, the EditField never sees it.  And you can paint it in a light color to make it clear this is not actually input. 

 

Here is some sample code, note that I have cut/pasted this from a working application, but changed a few things that I think are not related - but this might have screwed it up completely.....

 

    private BasicEditField _searchField = new BasicEditField("", "" ) {
        String emptyString = "Enter search characters";
        protected void paintBackground( Graphics g ) {
            g.setBackgroundColor(0x00FFFFFF);
            g.clear();
        }
        protected void paint( Graphics g ) {
            int oldColor = g.getColor();
            try {
                g.setColor( 0x00000000 );
                String test = super.getText();
                if ( test == null || test.length() < 1 ) {
                    g.setColor( 0x00808080 );
                    g.drawText(emptyString, 0, 0);
                }
                super.paint(g);
            } finally {
                g.setColor( oldColor );
            }
        }
    };

 

 

Please use plain text.
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: Prompt/hint/place holder text on a Numeric/Password edit field

Thanks Peter,

 

The solution works perfectly fine for me..:smileyhappy: I just over-ride the paint(), and everything falls into place..no changing the fliter at all..!!

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Prompt/hint/place holder text on a Numeric/Password edit field

Excellent.

 

I must admit I too tried putting onFocus and onUnfocus code to replace the text in the Field, before I decided to try this.  So you are not the only one who has fought that battle and lost!

Please use plain text.
Developer
silver20
Posts: 455
Registered: ‎03-04-2011
My Device: Paper cup

Re: Prompt/hint/place holder text on a Numeric/Password edit field

That's a cool solution, I'd have messed with onFieldChanged, detecting what they typed and replacing the text.

 

U.S. Patent #20157028:  Ghost Hints

 

Please use plain text.