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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:03:55+00:00 2026-05-30T14:03:55+00:00

I have been looking online for some time now to make sure there was

  • 0

I have been looking online for some time now to make sure there was not already one of these on here, but for some reason I cannot seem to find the exact way to make this work, and after 4 hours of trying I figured I would ask the experts.

I have my class right now that is suppose to have a onFocusChangeListener when the window is loaded that is suppose to trigger when I click my background causing the softkeyboard to be hidden.

So the short of the long is: how can I fix my class to listen for when I click my background and make my keyboard hidden.

Here is my code so far: (keep in mind I have made my layout both focusable and clickable)

package com.example.haymaker;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class addAppointment extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.appointment);
    final EditText appointmentName = (EditText) findViewById(R.id.editText1);

    appointmentName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(appointmentName.getWindowToken(), 0);

            }
        }
    });


    }

}

Thanks for your assistance

  • 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-05-30T14:03:56+00:00Added an answer on May 30, 2026 at 2:03 pm

    This is a little unusual, the android pattern is generally to let users close the keyboard using the back button.

    If you really want to close it when they touch outside of the edit text, you can add an onTouch listener(s) to your primary view and hide the keyboard:

    findViewById(R.id.you_main_view).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent e){
            if (e.getAction() == MotionEvent.ACTION_UP) hideSoftKeyboard();
            return false;
        }
    }
    

    This is a little tricky because your containing view may not get to handle touches to subviews (like list views for example) that handle touches themselves. You may have to add a couple of similar touch listeners to different views to get the entire screen to register a hit. Make sure your touch listeners return false, or otherwise they will swallow clicks you expect to be handled elsewhere.

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

Sidebar

Related Questions

I have been looking online for some time now, but I still haven't figured
I'm needing some help with mod rewriting. I have been looking online for the
I have been looking at the NSFetchedResultsControllerDelegate Protocol Reference and some sample code online
I have been working with managing agile teams for quite some time. Now I'm
I have been looking around online for a while now for methods of integration
I have been looking online to find documentation for the function in QTP and
I have been looking at examples online, and tutorials, and I cannot find anything
I have been looking at paypal for a online transaction, but I wanted to
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking into AWS spot instances for some jobs however instead of

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.