1

I've created a searchable activity as described here: http://developer.android.com/guide/topics/search/search-dialog.html. When the user presses the hardware search button, it shows a search bar in the top and keyboard in the bottom.

How can I get the search bar and keyboard to appear when the activity is launched, as if I'd pressed the hardware button?

The reason I don't just create a layout with an EditText and a Button is that I want a consistent experience for the user, so the search bar should look the same whether invoked from the hardware button or from code.

Let me know if you need clarification.

Marmoy
  • 8,009
  • 7
  • 46
  • 74

1 Answers1

1

You can start a search from an Activity with onSearchRequested():

    /**
     * onCreate is called when Android starts this Activity from scratch.
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        onSearchRequested();
    }
David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
  • what a beautifully simple solution. Thanks!! – Marmoy Jul 12 '11 at 10:54
  • @David Caunt - Im using this implementation in the same activity that will eventually handle the search request. This causes the activity to be duplicated within the activity stack. Can you check out my question http://stackoverflow.com/questions/8936971/call-to-method-onsearchrequested-in-the-same-activity-that-handles-search-requ – dell116 Jan 20 '12 at 16:31