If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
demotics2002
Posts: 64
Registered: ‎07-15-2010
My Device: Storm 2 - 9550
My Carrier: Starhub
Accepted Solution

How to make a custom NumericTextFilter with an 'e'. Or how to set keypad to num lock.

Hi,

 

I just almost finished my first BB application (on Blackberry OS 5.0). I just have one last thing to fix and that is to make a custom NumericTextFilter that allows the character 'e' which stands for exponent. For example -1.23e5, that's -1.23 raised to 5.

 

public class MyRealDecimal extends TextFilter {
    private String acceptedCharacters = "-0123456789.eE'

    public char convert(char character, int status){
        if(!validate(character))
            return 0;
        return character;
    }

    public boolean validate(char character){
        if(acceptedCharacters.indexOf(character)!=-1)
            return true;
        return false;
    }

}
 

 

That piece of code just do the job. In Storm 2 the keypad displays numeric characters, the negative sign, the decimal, and the character 'e' or 'E'. But this is not exactly what I want because the keypad mode is defaulted to Alpha characters. The text field I have is mostly used for numeric and seldom use the character 'e'.

 

My question is how can I default the keypad mode to num (num lock) and change to 'ABC' only when there is a need to use 'e'?

 

I tried

 

public class MyRealDecimal extends NumericTextFilter

 The mode is good. Default keypad mode is num lock. When I change to [ABC] there I found 'E'. But when I press it, it enters '2' instead of 'E'.

 

I am now thinking of using the first one where I extend TextFilter instead of NumericTextFilter but then, can someone help me how can I set the key pad to Num Lock?

 

Thanks guys...

Please use plain text.
Developer
demotics2002
Posts: 64
Registered: ‎07-15-2010
My Device: Storm 2 - 9550
My Carrier: Starhub

Re: How to make a custom NumericTextFilter with an 'e'. Or how to set keypad to num lock.

I got it working...

 

 

public class RealDecimalFilter extends NumericTextFilter {
	
	private String acceptedCharacters = "-0123456789.eE";
	
	public char convert(char character, AbstractString text, int position,
			int status) {
		return convert(character, status);
	}
		
	public char convert(char c, int status) {
		if(!validate(c)){
			return 0;
		}
		return c;
	}

	public boolean validate(char c) {
		if(acceptedCharacters.indexOf(c)==-1)
			return false;
		else {
			return true;
		}
	}
	
	public boolean validate(char character, AbstractString text, int position) {
		return validate(character);
	}

}

 

 

Please use plain text.
Developer
demotics2002
Posts: 64
Registered: ‎07-15-2010
My Device: Storm 2 - 9550
My Carrier: Starhub

Re: How to make a custom NumericTextFilter with an 'e'. Or how to set keypad to num lock.

... works for non touch screen device only. :smileysad:

Please use plain text.
Developer
demotics2002
Posts: 64
Registered: ‎07-15-2010
My Device: Storm 2 - 9550
My Carrier: Starhub

Re: How to make a custom NumericTextFilter with an 'e'. Or how to set keypad to num lock.

[ Edited ]

it now works for all. thanks to me.

 

import net.rim.device.api.ui.text.NumericTextFilter;
import net.rim.device.api.util.AbstractString;

public class RealDecimalFilter extends NumericTextFilter {
	
	private String acceptedCharacters = "-0123456789.eE";
	
	public char convert(char character, AbstractString text, int position,
			int status) {
		return convert(character, status);
	}
		
	public char convert(char c, int status) {
		if(status == 1){
			if(c=='2') c = 'e';
		} else if(status ==0){
			switch(c){
			case 'i': c = '-'; break;
			case 'e': c = '2'; break;
			case 'w': c = '1'; break;
			case 'r': c = '3'; break;
			case 's': c = '4'; break;
			case 'd': c = '5'; break;
			case 'f': c = '6'; break;
			case 'x': c = '8'; break;
			case 'c': c = '9'; break;
			}
		}
		if(!validate(c)){
			return 0;
		}
		return c;
	}

	public boolean validate(AbstractString text){
		return true;
	}

	public boolean validate(char c) {
		if(acceptedCharacters.indexOf(c)==-1)
			return false;
		else {
			return true;
		}
	}
	
	public boolean validate(char character, AbstractString text, int position) {
		return validate(character);
	}

}

 

Please use plain text.
Contributor
curro86
Posts: 35
Registered: ‎06-14-2010
My Device: Blackberry Curve 8530
My Carrier: Telcel

Re: How to make a custom NumericTextFilter with an 'e'. Or how to set keypad to num lock.

Thank you sir, great help!

Please use plain text.
New Developer
mcmordie
Posts: 50
Registered: ‎01-22-2009
My Device: Z10
My Carrier: Rogers

Re: How to make a custom NumericTextFilter with an 'e'. Or how to set keypad to num lock.

Wow-- I guess you know the frustration I just went through trying to get NumericTextFilter to work with a touchscreen. I wish I had found this post first. Great work!
Please use plain text.