BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-10-2007, 03:37 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Dec 2007
Model: 8800
PIN: N/A
Carrier: vodafone
Posts: 21
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default key listener in form

Please Login to Remove!

Hi is it possible to use keylistener in a form? for example when the user press the enter key, i will execute something. similar to how a command button would work on a form screen. thanks in advance
Offline  
Old 12-10-2007, 04:02 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

sure. overwrite keyChar, handle the things you want and relay the rest to super.keyChar

hth,
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-10-2007, 05:00 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Dec 2007
Model: 8800
PIN: N/A
Carrier: vodafone
Posts: 21
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks. do you have an example of how to do key listeners on a normal canvas class?

i read that i need to implement public boolean keyChar(char key, int status, int time)?

does this keyChar act like a protected void keyPressed(int k) or do i implement the keyChar inside the keyPressed method? im new to blackberry developing and hoping if you can gvie me a starting point to help me implement key char's for blackberry devices and how i can execute it during a form screen. thanks
Offline  
Old 12-10-2007, 10:31 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you override a canvas's keychar method by extending that class into a custom class and implementing the keychar method. therein, you capture the key and choose to do something with it, or simply move it on to the super.keyChar if you want it handled as it otherwise would be
Offline  
Old 12-11-2007, 03:12 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Dec 2007
Model: 8800
PIN: N/A
Carrier: vodafone
Posts: 21
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks. here is what i done, i added import net.rim.device.api.ui.Screen;

and then
public class MainCanvas extends Canvas implements CommandListener, Runnable, net.rim.device.api.system.Characters


i then added this:

Code:
    public boolean keyChar(char key, int status, int time)
    {
        if(key ==  net.rim.device.api.system.Characters.ENTER)
        {
            login();
        }
       return true;
   }

I then later added the net.rim.device package located from the blackberry simulator program i downloaded through netbeans version 5. when i try to compile it, it doesnt work.

i get a host of warning messages from the output window with these types of information:

Quote:
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.internal.phone.api.AddressBook DependentObject
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.api.framework.model.Persistabl eRIMModel
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.api.framework.model.FieldProvi der
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.internal.phone.api.CallerIDPro vider
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.api.framework.model.DefaultPro vider
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.api.framework.model.Conversion Provider
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.api.framework.model.Encryptabl eProvider
Warning: net.rim.device.apps.internal.phone.data.CallerIDIn fo: can't find superclass or interface net.rim.device.apps.api.framework.model.SyncFieldI DProvider

does anybody have any idea what im doing wrong :( thanks in advance
Offline  
Old 12-11-2007, 09:45 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

it looks like an error somewhere else. what version of the simulator are you running (OS version, 4.X) and where are you extending net.rim.device.apps.internal.phone.data.CallerIDIn fo
Offline  
Old 12-12-2007, 03:08 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Dec 2007
Model: 8800
PIN: N/A
Carrier: vodafone
Posts: 21
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by bemshaswing View Post
it looks like an error somewhere else. what version of the simulator are you running (OS version, 4.X) and where are you extending net.rim.device.apps.internal.phone.data.CallerIDIn fo
im using windows xp sp2, the latest simulator 4.3.0 and i am pointing to x:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\lib which conatins the net_rim_api jar file and added that has a library package from within java netbeans 5.5 project properties
Offline  
Old 12-12-2007, 11:18 AM   #8 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hm, I haven't toyed with 4.3 enough. I'd say try it on a 4.2.1 which is perhaps more stable.
Offline  
Old 12-14-2007, 04:04 AM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: Dec 2007
Model: 8800
PIN: N/A
Carrier: vodafone
Posts: 21
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

right i have had a look at the item state listeners, ItemCommandListener and ImageItem , and from what i have gathered so far, i can set a item command listener but what i want is to not use the command button keys, i would like to somehow use the keypressed method from within a form screen, not a command button as i am trying to add a simple button image in a form that when the user selects and presses the enter key on there blackberry or similar device, it will execute the keypressed method.


i have managed to achieve something similar by launching a the form from a thread class and that thread continues to check and see if the user has pressed the enter key from a textfield. basicly from a text field i can press the enter key and bam it works.

unfortunatly thats not what the client wants and therefore wants some kind of button in a form
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.