02-06-2013 10:15 AM
i need to make basic edit field take only range of numbers
i use filteration to only accept numeric value but i need more it to only accept range of data
exp {5:20}
02-06-2013 05:57 PM
The easiest option is to implement a FieldChangeListener and reset the value if not in range. Adding a FieldChangeListener is comonnly done - search the forum for more and look for the API..
02-07-2013 07:53 AM
eField = new EditField(" Enter Name: ", Message[1])
{
protected boolean keyChar(char ch, int status, int time)
{
//What ever you dont want
if(ch=='1'){
return true;
}
if (CharacterUtilities.isLetter(ch) || CharacterUtilities.isDigit(ch) || (ch == Characters.BACKSPACE)|| (ch == Characters.SPACE)||(ch == Characters.ESCAPE))
{
if( this.getText().length()>=10&&(ch != Characters.BACKSPACE)&&(ch != Characters.ESCAPE)){
Status.show("10 Letters Max");
return true;
}
return super.keyChar(ch, status, time);
}
return true;
}
protected void paint(Graphics g){
g.setGlobalAlpha(255);
g.setColor(Color.WHITESMOKE);
super.paint(g);
}
};
02-07-2013 08:44 AM
I would not recommend a keyChar listener for any processing unless you know that are only going to run on a device with a full keyboard. I have had issues doing this sort of processing on reduced key board models and virtual keyboards. FieldChangedListener works well - just make sure you don't invoke it recursively.....