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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:46:11+00:00 2026-05-24T09:46:11+00:00

In my application I am using the Action Bar with a custom SearchView in

  • 0

In my application I am using the Action Bar with a custom SearchView in it. I want to use some custom code when the user hits the enter button in the search field. But I cant find a way to catch the moment the user hits the enter button in the SearchView.

Now I tried several ways to capture the search action but I cant seem to find it.

My button is defined like this:

<item
    android:id="@+id/action_bar_search"
    android:title="Search"
    android:icon="@drawable/ic_menu_search"
    android:showAsAction="always"
    android:actionViewClass="-package-.CustomSearchView"
    />

With this belongs the CustomSearchView class:

public class CustomSearchView extends SearchView implements OnClickListener, android.view.View.OnKeyListener{

    public CustomSearchView(Context context) {
        super(context);
        this.setOnSearchClickListener(this);
        this.setSubmitButtonEnabled(true);
            this.setOnClickListener(this);
        this.setOnKeyListener(this);
    }

    @Override
    public void onClick(View v) {

        Log.d("SEARCH", "Onclick! " + this.getQuery());
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub

        Log.d("SEARCH", "Search onkey");
        return false;
    }

}

Here you can see that I`ve tried 2 approaches:

  1. Catch the onclick event from the submit button. That didnt work
    since it only fired when I clicked on the search icon to open the
    SearchView.
  2. Catch keystrokes within the SearchView. That didnt work
    either. Got no response from any key that I pressed there.

Does anyone have a way of making a custom Search action with this SearchView?

UPDATE:

As stated below by PJL: You dont need a custom dialog for overriding this behaviour. The normal SearchView widget will work just fine for this.

  • 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-24T09:46:13+00:00Added an answer on May 24, 2026 at 9:46 am

    Get your search view and add an OnQueryTextListener

    final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // Do something
            return true;
        }
    
        @Override
        public boolean onQueryTextSubmit(String query) {
            // Do something
            return true;
        }
    };
    
    searchView.setOnQueryTextListener(queryTextListener);
    

    By the way my menu layout is as follows;

    <item android:id="@+id/menu_search"
        android:showAsAction="ifRoom"
        android:actionViewClass="android.widget.SearchView" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Swing application I am using a bar-code scanner attached to the machine
In my application I am using the new Action Bar Compatibility sample from Google
I am using actionbarsherlock library to have action-bar in my application, I am also
is it possible to generate cross-application action links using the HTML helper class? I
I have a web application using ASP.NET 2.0 and I want to know if
I am having trouble using some UIButtons to call actions in my Tab Bar
In my Android application I need to have a black action bar and my
I want to display a progress bar while doing some work, but that would
I've added a SearchView to ActionBar of my application, and setup a SuggestionsProvider using
I added toolbar to on screen of navigation based application using the following code

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.