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 8935773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:04:14+00:00 2026-06-15T10:04:14+00:00

I have an activity that is showing an EditText and two bottoms. When I

  • 0

I have an activity that is showing an EditText and two bottoms.

When I tap on the EditText the Android Virtual Keyboard shows up so that I can type in my text.
Now, before tapping in any bottom I would like to hide the keyboard. I would like to do it by tapping on the screen.

I have seen posts here in stackoverflow with some similar question but that does not look like working.
I have tried to set a listener:

   // Create an anonymous implementation of OnFocusChangeListener
   private OnFocusChangeListener mFocusListener = new OnFocusChangeListener() {
       public void onFocusChange(View v, boolean b) {
          // do something when the focus changes
        hideSoftKeyboard(v);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setupUI(findViewById(R.id.parent));
        EditText editText = (EditText) findViewById (R.id.edit_message);
        editText.setOnFocusChangeListener(mFocusListener);
        setContentView(R.layout.activity_main);
    }

I have also tried to create a parent activity that recursively associate an onTouch event to every view that is not a text View but it does register only the text view (I took this piece of code from another stackoverflow post)

    public void setupUI(View view) {

    //Set up touch listener for non-text box views to hide keyboard.
    if(!(view instanceof EditText)) {

        view.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                hideSoftKeyboard(v);
                return false;
            }

        });
    }

    //If a layout container, iterate over children and seed recursion.
    if (view instanceof ViewGroup) {

        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {

            View innerView = ((ViewGroup) view).getChildAt(i);

            setupUI(innerView);
        }
    }
}

Any straitgh forward solution for this? I can not believe that there is not a more simple way to do this.
I am using Gingerbread API (API Level 10)

Thanks

  • 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-15T10:04:15+00:00Added an answer on June 15, 2026 at 10:04 am

    Ok, I found a way to do this in a very simple way:
    XML Layout definition. Since a Layout is a ViewGroup we can implement events on it.
    Go and define the method to handle a click on the layout (hideSoftKeyboard)

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" 
        android:id="@+id/main_layout" 
        android:onClick="hideSoftKeyboard" >
    

    And here is how I implemented the method:

    public void hideSoftKeyboard(View view) {
        InputMethodManager inputMethodManager = (InputMethodManager)  getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that shows some TextView s and EditText s, as well
I have an Activity that should only get created once. That is, onCreate can
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity on an Android Application that starts a Sync Process with
I have activity records that have an inline formset showing appointments. I use the
I have an Android Activity that uses a class that I developed that extends
I have an activity with two fragments: one for showing products in a grid
I have an activity that when users press share on a file it would
I have an activity that some times OutOfMemory exception occurs in some parts of
I have an activity that I'd like to load from a preference screen. I'm

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.