Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:36:44+00:00 2026-06-08T17:36:44+00:00

In android, I can do like that where user can click outside of editview

  • 0

In android, I can do like that where user can click outside of editview to hide the virtual keyboard.

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    View v = getCurrentFocus();
    boolean ret = super.dispatchTouchEvent(event);

    if (v instanceof EditText) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w
                        .getBottom())) {

            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus()
                    .getWindowToken(), 0);
        }
    }
    return ret;
}

What about in blackberry? I want to run for VirtualKeyboard.isSupported() only.

Update

public class Custom_EditField extends EditField {
private int width, row, color;
private MainScreen mainscreen;

Custom_EditField(long style, int width, int row, MainScreen mainscreen) {
    super(style);
    this.width = width;
    this.row = row;
    this.mainscreen = mainscreen;
}

public int getPreferredHeight() {
    return Font.getDefault().getHeight() * row;
}

public int getPreferredWidth() {
    return width;
}

protected void onFocus(int direction) {
    if (VirtualKeyboard.isSupported())
        mainscreen.getVirtualKeyboard().setVisibility(
                VirtualKeyboard.SHOW_FORCE);
    invalidate();
    super.onFocus(direction);
}

protected void onUnfocus() {
    if (VirtualKeyboard.isSupported())
        mainscreen.getVirtualKeyboard().setVisibility(
                VirtualKeyboard.HIDE_FORCE);
    invalidate();
    super.onUnfocus();
}

public boolean isFocusable() {
    return true;
}

protected void layout(int maxWidth, int maxHeight) {
    super.layout(maxWidth,
            Math.min(maxHeight, Font.getDefault().getHeight() * row));
    super.setExtent(maxWidth,
            Math.min(maxHeight, Font.getDefault().getHeight() * row));
}

protected void paint(Graphics graphics) {
    int rectHeight = getPreferredHeight();
    int rectWidth = getPreferredWidth();
    try {
        color = Color.BLACK;
        graphics.setColor(color);
        graphics.drawRect(0, 0, rectWidth, rectHeight);
        super.paint(graphics);
    } finally {
        graphics.setColor(color);
    }
}
}

This editfield will hide the keypad if you click on another field but not anypoint.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:36:45+00:00Added an answer on June 8, 2026 at 5:36 pm

    I have this utility code for showing, or hiding the keyboard. This should be valid for OS 4.7 and above. Let me know if you need to support lower OS versions.

       /** Hides the virtual keyboard, if there is one showing. */
       public static void hideKeyboard() {
          VirtualKeyboard kb = UiApplication.getUiApplication().getActiveScreen().getVirtualKeyboard();
          if (kb != null) {
             kb.setVisibility(VirtualKeyboard.HIDE);
          }
       }
    
       /** @return TRUE if the virtual keyboard is hidden, or not supported */
       public static boolean isKeyboardHidden() {
          if (VirtualKeyboard.isSupported()) {
             VirtualKeyboard kb = UiApplication.getUiApplication().getActiveScreen().getVirtualKeyboard();
             if (kb != null) {
                int visibility = kb.getVisibility();
                return ((visibility == VirtualKeyboard.HIDE)
                        || (visibility == VirtualKeyboard.HIDE_FORCE));
             }
          }
          return true;
       }
    

    Note that I made these static functions. So, if you put them in a class named UiUtilities, then you would call them like:

     if (!UiUtilities.isKeyboardHidden()) {
         UiUtilities.hideKeyboard();
     }
    

    As far as where to trigger this code, here’s what I recommend, instead of overriding onUnfocus(). I’m not sure this is the easiest, or most efficient way to solve the problem (so I welcome other answers!), but I think this will work.

    I told you a couple answers ago that you normally should not override the touchEvent() method in your code. For things like normal buttons, I think that’s true. This might be one example where you need to. You should have a Manager (or VerticalFielManager, or similar) that represents the screen that this EditField is on. In that manager, implement the touchEvent() method like this:

    import net.rim.device.api.ui.TouchEvent;
    
       protected boolean touchEvent(TouchEvent event) {
          // We take action when the user completes a click (a.k.a. unclick)
          int eventCode = event.getEvent();
          if ((eventCode == TouchEvent.UNCLICK) || (eventCode == TouchEvent.DOWN)) {
             // Get the touch location, within this Manager
             int x = event.getX(1);
             int y = event.getY(1);
    
             if ((x >= 0) && (y >= 0) && (x < getWidth()) && (y < getHeight())) {
                int field = getFieldAtLocation(x, y);
                if (field >= 0) {
                   // Let event propagate to child field
                   return super.touchEvent(event);
                } else {
                   if (eventCode == TouchEvent.UNCLICK) {
                      // A completed click anywhere else in this manager should dismiss the keyboard
                      UiUtilities.hideKeyboard();
                   } else {
                      // This is just a soft touch (TouchEvent.DOWN), without full click
                      setFocus();
                   }
                   // Consume the event
                   return true;
                }
             }
          }
          // Event wasn't for us, let superclass handle in default manner
          return super.touchEvent(event);
       }
    

    Try that. You might need to change my logic, depending on whether you want to hide the keyboard for a full click, versus a simple touch down (if you’re new to BlackBerry, it might not be clear what the difference between those are). But, I think this should get you close(r).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In android, my app provides a button that the user can click to return
I would like to make a manual of the android APIs that can be
For Android GUI: I would like to create a window that I can pull
I have a button that the user can click which sends them to the
On a touch device like iPhone/iPad/Android it can be difficult to hit a small
In android the Toggle buttons are looks like below - Can we modify this
Friends, I like to know using which version of Android SDK we can develop
How can you implement a RadioButtonPreference in android? Just like the CheckBoxPreference . Are
How can i find nth ROW from SQLiteDatabase in android, i want something like
Is Android development restrictive in any way like the iPhone , or can you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.