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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:32:30+00:00 2026-06-09T07:32:30+00:00

I know this question has been asked million times, but I’m not able to

  • 0

I know this question has been asked million times, but I’m not able to find a direct solution for my specific problem.

In my SearchActivity, there is a EditText & a ListView.

I want even if the user touches anywhere except EditText, the keyboard should close.

What I’ve done is setup a TouchListener on ListView & whenever it is touched, the keyboard is closed.

But it is creating a problem that when I touch on any element of the ListView, the keyboard hides, but the element of the list becomes invisible.

Please suggest a better approach than this.

My Code:

public class SearchActivity extends Activity implements OnTouchListener {

    RelativeLayout rlSearchLayout;
    EditText etSearchBar;
    ListView lvSearchResult;
    private static String searchText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        setTitle("SearchActivity.java");

        etSearchBar = (EditText) findViewById(R.id.etSearchBar);
        lvSearchResult = (ListView) findViewById(R.id.lvSearchResult);

        searchText = etSearchBar.getText().toString();
        lvSearchResult.setOnTouchListener(this);

        String[] objects = { "One", "two" };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, objects);
        lvSearchResult.setAdapter(adapter);
    }

    @Override
    public boolean onTouch(View paramView, MotionEvent paramMotionEvent) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(etSearchBar.getWindowToken(), 0);

        return false;
    }
}
  • 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-09T07:32:33+00:00Added an answer on June 9, 2026 at 7:32 am

    Add this to your layout file.

     <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#80000000"
        />
    

    Now add a TouchListener for this imageView in your activity.

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

Sidebar

Related Questions

I know this question has been asked many times before but I can't find
Hey all, I know this question has been asked a million times before but
I know this question has been asked lots of times, but I am not
I know this question has been asked multiple times, but nobody has been able
I know this question has been asked a zillion times, but I still feel
I know this question has been asked before, but I haven't been able to
I know this question has been asked before numorous times but they seem to
I know this question has been asked countless of times. But none of them
Yes, I know this question has been asked before, but I can't find an
Yes, I know this question has been asked a lot of times, but I

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.