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
Regular Contributor
amr3434
Posts: 81
Registered: ‎01-16-2012
My Device: BOLD 9650 + developer
My Carrier: Vodafone

BasicEditField With range ??

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}  


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

Re: BasicEditField With range ??

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..

Please use plain text.
Contributor
Yashil
Posts: 12
Registered: ‎01-19-2013
My Device: curve 8520
My Carrier: vodacom

Re: BasicEditField With range ??

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);
}

};

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

Re: BasicEditField With range ??

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.....

Please use plain text.