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
Highlighted
Developer
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
My Carrier: _
Accepted Solution

How to hide the keyboard programmatically

When i enter the value EditField then keyboard appear but when user press on any button then keyboard should be hide. Is there any way to hide the keyboard.

 

I am facing problem that when keyboard appear in login screen then it distort the layout of next screen. Home screen will become small.

 

Thanks in advance.

Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: How to hide the keyboard programmatically

Hi Ajay,

You can hide the virtual keyboard by placing the following code--

 

if(VirtualKeyboard.isSupported())        UiApplication.getUiApplication().getActiveScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);
Rishikesh Singh
Developer
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
My Carrier: _

Re: How to hide the keyboard programmatically

Thanks for your reply,

 

I used this code

 

UiApplication.getUiApplication().getActiveScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);

 

But its not working in BB 6.

 

Please help me why its so.

 

Thanks in advance.

 

 

bh

Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: How to hide the keyboard programmatically

could you please put part of your code where you are using this??
Rishikesh Singh
Developer
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
My Carrier: _

Re: How to hide the keyboard programmatically

Here is my code

 

 mAddButtonField.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                showAddResult();
           UiApplication.getUiApplication().getActiveScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);
            }
        });

 

Please help me..

Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: How to hide the keyboard programmatically

In the initial post you asked--
"When i enter the value EditField then keyboard appear but when user press on any button then keyboard should be hide. Is there any way to hide the keyboard."


So ideally you should overright the following methods of EditField--

 

protected void onFocus(int direction) {
        if (VirtualKeyboard.isSupported()) {
            this.getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.SHOW);
        }
             super.onFocus(direction);
    }

    protected void onUnfocus() {
        if (VirtualKeyboard.isSupported()) {
            this.getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);
        }
             super.onUnfocus();
    }

 

 

As there is no point in showing keyboard when you are not making any input.

Rishikesh Singh
Developer
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
My Carrier: _

Re: How to hide the keyboard programmatically

Thanks.. I was doing like that. Once user enter the credential in the login screen the tap on login button then i hide the keyboard programmatically.

 

Its was working in simulator but not on device. Please help me why its so

 

Thanks in advance.

Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: How to hide the keyboard programmatically

Sorry i may not be getting you correctly. But the above work well for me.

 

please look at the following post, it may help you.

 

http://stackoverflow.com/questions/11718548/how-to-auto-hide-virtual-keypad-when-touch-out-of-editfi...

 

Thanks

Rishikesh Singh