BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Trying to restrict characters entered into a BasicEditField control (http://www.blackberryforums.com/showthread.php?t=53509)

forcedfx 11-06-2006 07:59 PM

Trying to restrict characters entered into a BasicEditField control
 
I've been racking my brain trying to figure this out for two days now.

I have a BasicEditField buit into a MainScreen that is used for entering the MAC address of a network adapter.

The field is only supposed to accept the characters 0-9, a-f, and A-F. What I want to do is grab each character as the user enters it and decide whether to keep it or discard it. None of the pre-defined Filters will work for this field. Is there a way to create my own filter? That would be ideal.

Anyway, I tried overriding the keyChar, keyDown, and keyControl events but none of them seem to give me what I want. The keyChar event is not being called when I enter letters or numbers into the BasicEditField, but when I press the backspace key it does work. And I don't think keyDown and keyControl are what I need.

All of the documentation I've read on this event seems to state that it will report each character that is entered.

I've also tried using a FieldChangeListener to examine the text every time it changes, but it's a cumbersome process and still doesn't work the way I want it to.

jbartel 11-07-2006 01:53 PM

Have you tried using a net.rim.device.api.ui.text.HexadecimalTextFilter? It does not allow lower case a-f but will convert the lower case ones to uppercase as the user types them.

BasicEditField has a setFilter method to set a TextFilter for the field. If the built-in HexadecimalTextFilter does not meet your needs you can extends the TextFilter class to create a custom filter that does whatever you want it to do.

forcedfx 11-07-2006 02:43 PM

I tried using the hex filter but it does not seem to work correctly. It filters out all numbers and allows me to enter letters, such as, "S" when it should not.

Do you know where I can find resources on the custom filter? I have another text field that can only allow certain characters so I would be needing it there as well. If I can define my own filter I can finally move on to another part of this project. I tried googling the custom text filter but all I found were definitions which didn't really help me, unfortunately.

rock_win 08-10-2007 04:37 AM

hi

any luck making custom filters......... i'm also stuck in a similar situation and would appreciate help on the subject.

bemshaswing 08-10-2007 08:39 AM

have you tried overriding keyCharUnhandled as well? That might help


All times are GMT -5. The time now is 01:49 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.