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
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile
Accepted Solution

keylistener 'escape' and 'enter'

[ Edited ]

I have some buttons on a global popupscreen. The first time I found [ENTER] works but [ESC] can not close the popscreen.So I add

 

public boolean keyChar(char key, int status, int time) {
       //intercept the ESC key - exit the app on its receipt
       if (key == Characters.ESCAPE)
           close();
       return false;
   }

 

for close the popscreen and it works well. But after that [ENTER] can not work.I dunno how to do so that it can still return to listen the filed. The full code is like the following:

final class pScreen extends PopupScreen implements KeyListener {
   public pScreen()
   {
     ...
       class addlistener implements FieldChangeListener {
     ...
       }
       class addlistener2 implements FieldChangeListener {
     ...
       }
       myButton.setChangeListener(new addlistener());
       myButton2.setChangeListener(new addlistener2());
   }
   public void close() {
       UiApplication.getUiApplication().popScreen(this);
   }
   public boolean keyChar(char key, int status, int time) {
      if (key == Characters.ESCAPE)
           close();
       if (key == Characters.ENTER)
           // How to do here so that I can still listen my buttons?
       return false;
   }

 Any help should be appreciated.

Best Regards,
Tiandi
www.tiandiyoyo.com
Highlighted
Developer
Posts: 26
Registered: ‎10-21-2009
My Device: Not Specified

Re: keylistener 'escape' and 'enter'

try this one for [ENTER].

 

return navigationClick(status, time);

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: keylistener 'escape' and 'enter'

Correct your code as follows:

 

   public boolean keyChar(char key, int status, int time) {
       //intercept the ESC key - exit the app on its receipt
       if (key == Characters.ESCAPE)
           close();
       return super.keyChar(key, status, time);
   }

 

Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: keylistener 'escape' and 'enter'

thx ,it works

Best Regards,
Tiandi
www.tiandiyoyo.com