04-06-2011 09:22 AM
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
Solved! Go to Solution.
04-06-2011 09:43 AM
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.
04-06-2011 10:02 AM
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.
04-06-2011 10:07 AM
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).
04-06-2011 10:15 AM
Thanks for clarifying,
This is what i have done :
04-06-2011 12:45 PM
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!
04-06-2011 01:58 PM
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 );
}
}
};
04-07-2011 03:59 AM
Thanks Peter,
The solution works perfectly fine for me..
I just over-ride the paint(), and everything falls into place..no changing the fliter at all..!!
04-07-2011 06:00 AM
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!
10-19-2011 06:14 AM
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