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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:42:59+00:00 2026-06-18T05:42:59+00:00

I am trying to Search in ActionbarSherlock ver 4.2 . ActionbarSherlock has backported SerchView

  • 0

I am trying to “Search” in ActionbarSherlock ver 4.2. ActionbarSherlock has backported SerchView in the latest version.

I have the following code in onCreateOptionsMenu of SherlockListFragment

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // Place an action bar item for searching.
        SearchView searchView = new SearchView(getSherlockActivity().getSupportActionBar().getThemedContext());
        searchView.setQueryHint("Search Friends");
        searchView.setIconified(true);

        menu.add(Menu.NONE, Menu.FIRST, Menu.FIRST, "Refresh")
                .setIcon(R.drawable.ic_action_refresh)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        menu.add(Menu.NONE, Menu.FIRST + 1, Menu.FIRST + 1, "Search")
                .setIcon(R.drawable.abs__ic_search)
                .setActionView(searchView)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    }

and the following code in the

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case Menu.FIRST:
            Toast.makeText(getActivity(),"FIRST", Toast.LENGTH_SHORT).show();
            break;
         case Menu.FIRST + 1:
             Toast.makeText(getActivity(),"FIRST+1", Toast.LENGTH_SHORT).show();
            break;
    }
    return super.onOptionsItemSelected(item);
}

I am getting Toast when I click on the “Refresh” button in the ABS but no response when when I click on the “search” it expands and gets converted into EditText but Toast is not fired.

My Question

How to integrate “search” in Actionbar with ABS?

  • 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-18T05:43:00+00:00Added an answer on June 18, 2026 at 5:43 am

    It works.

    For implementation of SearchView we need to implement callback interface like this

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    
                /**
                 * Called when the user submits the query. This could be due to a key press on the
                 * keyboard or due to pressing a submit button.
                 * The listener can override the standard behavior by returning true
                 * to indicate that it has handled the submit request. Otherwise return false to
                 * let the SearchView handle the submission by launching any associated intent.
                 *
                 * @param newText the query text that is to be submitted
                 * @return true if the query has been handled by the listener, false to let the
                 *         SearchView perform the default action.
                 */
                @Override
                public boolean onQueryTextSubmit(String newText) {
    
                    return true;
                }
    
    
                /**
                 * Called when the query text is changed by the user.
                 *
                 * @param newText the new content of the query text field.
                 * @return false if the SearchView should perform the default action of showing any
                 *         suggestions if available, true if the action was handled by the listener.
                 */
                @Override
                public boolean onQueryTextChange(String newText) {
    
                    ThizLog.d(TAG, "Inside onQueryTextChange");
                    // called when the action bar search text has changed.  Update
                    // the search filter, and restart the loader to do a new query
                    // with this filter.
                    String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                    // Don't do anything if the filter hasn't actually changed.
                    // Prevents restarting the loader when restoring state.
                    if (mCurFilter == null && newFilter == null) {
                        return true;
                    }
                    if (mCurFilter != null && mCurFilter.equals(newFilter)) {
                        return true;
                    }
                    mCurFilter = newFilter;
                    getLoaderManager().restartLoader(0, null, this);
                    return true;
                }
            });
    

    in this particular case we need to pass the text entered by the user to the CursorLoader and let it reload the cursor with the appropriate results.

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

Sidebar

Related Questions

I am trying to search for files which matches following expression with sed [a-zA-Z0-9]{1,10}\s{1,5}\
I'm trying to search in a LDAP server all the users that have some
I`m trying to request search from ActionBarSherlock. My class extends SherlockListActivity. This is how
I am trying to use the wonderful library by Jake; ActionbarSherlock(ABS) version 4.2. I
I am trying to search questions which have a given tag. How can you
I been trying to search a bit about this and I have faint memories
Trying to search where movies coming out have a release date greater than today's
I am trying to Search the Property By Price Range. I have attached My
I am trying to search using Apache Lucene index. For it i have created
I am trying to search employees based on their code and department. I triggered

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.