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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:41:20+00:00 2026-06-16T08:41:20+00:00

I’m currently using ActionBarSherlock 4.2 and it’s SearchView widget in my app. I wanted

  • 0

I’m currently using ActionBarSherlock 4.2 and it’s SearchView widget in my app.

I wanted to make it submit query even though it’s empty. I tried to set imeOptions and OnKeyListener but both were ignored without a reason.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    Log.d(TAG, "onCreateOptionsMenu");
    inflater.inflate(R.menu.interactive_map, menu);
    mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();

    mSearchView.setImeOptions(EditorInfo.IME_ACTION_GO);
    mSearchView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            Log.d(TAG, "keyCode: " + keyCode); 
            Log.d(TAG, "Action: " + event.getAction());
            if(keyCode == EditorInfo.IME_ACTION_SEARCH){
                onQueryTextSubmit(""+mSearchView.getQuery());
            }

            return false;
        }
    });


    super.onCreateOptionsMenu(menu, inflater);
}

onKey’s never get triggered as both Logcat entries never appear in Logcat window. Not sure if this being inside SherlockFragment is the problem.

Nothing special’s done to the menu item as well.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/action_search"
          android:title="@string/app_name"
          android:icon="@android:drawable/ic_menu_search"
          android:showAsAction="always"
          android:actionViewClass="com.actionbarsherlock.widget.SearchView" />
</menu>

Is there a way to get around this? Or is there simpler way to enable submitting when query is empty? It doesn’t seems to support any configuration in the source code though.

  • 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-16T08:41:21+00:00Added an answer on June 16, 2026 at 8:41 am

    I switched to put SearchView via ActionMode instead. I’ll accept this as an answer for now until someone has a better solution for this question.

    private void showActionMode(){
        MainActivity a = (MainActivity)getActivity();
        a.startActionMode(new SearchActionMode());
    }
    
    private class SearchActionMode implements ActionMode.Callback{
    
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            Log.d(TAG, "onCreateActionMode creating inflater");
            MenuInflater inflater = new MenuInflater(getActivity());
            Log.d(TAG, "onCreateActionMode inflating");
            inflater.inflate(R.menu.interactive_map, menu);
            Log.d(TAG, "onCreateActionMode finding SearchView");
            mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    
            Log.d(TAG, "mSearchView: " + mSearchView);
            setupSearchView();
            return true;
        }
    
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            Log.d(TAG, "onPrepareActionMode");
            //TODO add searchView once working
            mSearchView.requestFocus(); 
            return false;
        }
    
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            Log.d(TAG, "onActionItemClicked");
            return false;
        }
    
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            Log.d(TAG, "onDestroyActionMode");
            closeTopTray();
            closeListView();
        }
    
    }
    
    
    private void setupSearchView() {
    
        mSearchView.setIconifiedByDefault(false);
        mSearchView.setId(ID_SEARCH_VIEW);
        mSearchView.setOnSearchClickListener(this);
        mSearchView.setOnQueryTextListener(this);
        mSearchView.setOnCloseListener(this);
        mSearchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    
        // To automatically display keyboard when display SearchView
        mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
    
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                Log.d(TAG, "mSearchView focus changed: " + hasFocus);
                if (hasFocus) {
                    showInputMethod(v.findFocus());
                }
            }
        });
    
        mSearchView.setQueryHint("Type keyword");
        mSearchView.setQuery((TextUtils.isEmpty(searchQuery)? "": searchQuery), false);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.