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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:52:22+00:00 2026-06-16T00:52:22+00:00

I am trying to to implement SearchView with Sherlock Action Bar. I am not

  • 0

I am trying to to implement SearchView with Sherlock Action Bar. I am not able to get the query to enter the onQueryTextChange method. Not sure whats going wrong.

public class MainActivity extends SherlockFragmentActivity implements
        SearchView.OnQueryTextListener {
    protected static CharSequence[] _categories = { "Amusement Park",
            "Bird Sanctuary", "Wild Life", "River", "Hill Station", "Temple" };

    protected static boolean[] _selections = new boolean[_categories.length];

    private final String[] places = new String[] { "Mysore", "Bangalore",
            "Mangalore", "Wayanad", "Bandipur National Park", "Chickmaglur",
            "Bandipura", "Coorg", "Kodaikanal", "Hampi", "Ghati Subramanya",
            "Mekedatu", "Muththathhi", "Shivasamudram", "Talakadu",
            "Savana Durga" };

    public SearchView mSearchView;
    private TextView mStatusView;

    private Menu mainMenu = null;

    PlacesListAdapter adapter;
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i("Nomad", "onCreate");

        List<Place> thePlaces = new ArrayList<Place>();
        for (int i = 0; i < places.length; i++) {
            Place pl = new Place("NO_ID", places[i], "NO_DISTANCE",
                    "NO_CATEGORYICON");
            thePlaces.add(pl);
        }

        listView = (ListView) findViewById(R.id.place_list);
        adapter = new PlacesListAdapter(MainActivity.this, R.layout.item_place,
                thePlaces);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View view, int position,
                    long id) {

                Toast.makeText(MainActivity.this, "Test", Toast.LENGTH_SHORT);
                startActivity(new Intent(MainActivity.this, PlaceActivity.class));
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        Log.i("Nomad", "onCreateOptionsMenu");
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);

        mainMenu = menu;

        MenuItem searchItem = menu.findItem(R.id.action_search);

        // Search View
        mSearchView = (SearchView) searchItem.getActionView();
        setupSearchView(searchItem);

        mSearchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // hide action item
                if (mainMenu != null) {
                    mainMenu.findItem(R.id.action_category).setVisible(false);
                    mainMenu.findItem(R.id.action_sort).setVisible(false);
                }

            }
        });
        mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                // re-show the action button
                if (mainMenu != null) {
                    mainMenu.findItem(R.id.action_category).setVisible(true);
                    mainMenu.findItem(R.id.action_sort).setVisible(true);
                }
                return false;

            }
        });

        Log.i("Nomad", "after setupSearchView()");
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {

        case R.id.action_search:
            Toast.makeText(this, "Searh", Toast.LENGTH_LONG).show();
            Log.i("Nomad", "Click Search");
            break;

        case R.id.action_category:
            showDialog();
            break;
        case R.id.action_sort_alpha_az:
            Toast.makeText(this, "Alpha AZ", Toast.LENGTH_LONG).show();
            break;
        case R.id.action_sort_alpha_za:
            Toast.makeText(this, "Alpha ZA", Toast.LENGTH_LONG).show();
            break;
        case R.id.action_sort_dist_nf:
            Toast.makeText(this, "Dist NF", Toast.LENGTH_LONG).show();
            break;
        case R.id.action_sort_dist_fn:
            Toast.makeText(this, "Dist FN", Toast.LENGTH_LONG).show();
            break;
        default:
            // return super.onOptionsItemSelected(item);
            break;
        }
        return true;
    }

    private void setupSearchView(MenuItem searchItem) {
        mSearchView.setIconifiedByDefault(true);
        mSearchView.setOnQueryTextListener(this);
        mSearchView.setSubmitButtonEnabled(false);

        searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
        // | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
    }

    public boolean onQueryTextChange(String newText) {
        Log.i("Nomad", "onQueryTextChange");

        if (TextUtils.isEmpty(newText)) {
            Log.i("Nomad", "onQueryTextChange Empty String");
            listView.clearTextFilter();
        } else {
            Log.i("Nomad", "onQueryTextChange " + newText.toString());
            adapter.getFilter().filter(newText.toString());
        }
        return true;
    }

    public boolean onQueryTextSubmit(String query) {
        Log.i("Nomad", "onQueryTextSubmit");
        return false;
    }

    public boolean onClose() {
        Log.i("Nomad", "onClose");
        return false;
    }

    protected boolean isAlwaysExpanded() {
        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-16T00:52:23+00:00Added an answer on June 16, 2026 at 12:52 am

    Add this to your searchCommand :

    searchCommand.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
Trying to implement AVAudioplayer and get some metering data of the played music, but
trying to implement the following but its not working <script> function loadmap(lat,lng) { //alert(lat,lang);
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
Trying to implement sticky footer but its not working as planned. It throws it
Trying to implement links in my foreach loop. However, can't get the $category link
I am trying implement an alphabetical range to perform a query in Solr 3.3.
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
I am trying implement a most recent widget into my tumblr post. So far,

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.