TextField - show a hint before the user starts typing

I am developing a Blackberry application. I want to show tooltip text in a TextField before the user starts typing. When the user starts typing, he should disappear, and when 0 characters appear in the TextField, he should appear. Has anyone else implemented this ?, please share.

+4
source share
3 answers

here is the implementation in the paint () method

String test = super.getText(); if ( test == null || test.length() < 1 ) { graphics.setColor( 0x00a0a0a0 ); graphics.drawText(hint, 0, 0); } 

and here is the source, thanks to peter_strange http://supportforums.blackberry.com/t5/Java-Development/Prompt-hint-place-holder-text-on-a-Numeric-Password-edit-field/mp/990817#M151704

+2
source
 protected void paint(Graphics g) { if(super.getText().length() == 0) { g.setColor(Color.GRAY); g.drawText("MMYY", 0, 0); } g.setColor(Color.BLACK); super.paint(g); }; 
+7
source

Here is my attempt - this is the complete code, you can run it in JDE 6.x.

When you enter something, the gray β€œSearch” line will disappear:

screenshot

border.png:

border.png

src \ mypackage \ MyEdit.java:

 package mypackage; import net.rim.device.api.system.*; 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.ui.decor.*; public class MyEdit extends UiApplication { public static void main(String args[]) { MyEdit app = new MyEdit(); app.enterEventDispatcher(); } public MyEdit() { pushScreen(new MyScreen()); } } class MyScreen extends MainScreen { Border myBorder = BorderFactory.createBitmapBorder( new XYEdges(20, 16, 27, 23), Bitmap.getBitmapResource("border.png")); BasicEditField myField = new BasicEditField(TextField.NO_NEWLINE) { protected void paint(Graphics g) { if (getTextLength() == 0) { g.setColor(Color.LIGHTGRAY); g.drawText("Search", 0, 0); } g.setColor(Color.BLACK); super.paint(g); } }; public MyScreen() { myField.setBorder(myBorder); setTitle(myField); } } 
+4
source

All Articles