1

I have a main activity that, among other elements, has a search view on screen. When a client clicks on the search box (and makes an entry) I need to invoke an activity that will provide results to populate other places on that activity screen.

I've looked at a ton of StackOverflow (and other) threads about implementing search view (am using the widget) - most either refer to using the action bar or a separate search activity window. Neither are options in this case.

Without lectures on why I should use the action bar, does anyone have the very basics on using search? In effect, when they enter info in it and click the search icon (magnifying glass) I want to listen for a click/search on that item, call a function to get the contents of that (as in intent.getStringExtra(SearchManager.QUERY);), do some work and go from there. However, I'm not successful in hooking in to when the search icon on the keyboard is pressed and getting the user's search line. Any ideas?

Thanks

Tab
  • 155
  • 9

1 Answers1

2

Okay, finally figured it out. Oh so often I'll look at something for hours, finally post a question, then figure it out 20 minutes later. Oh, well. Hopefully this helps someone else:

What I've got is an embedded search view in another activity and I just want to hook into it like I would a button. I found lots of stuff regarding action bars and xml intents and all that crap, but what I really wanted turned out to be this:

Make sure to import the listener: import android.widget.SearchView.OnQueryTextListener;

Say that you implement it: public class MainActivity extends Activity implements OnQueryTextListener {

Then just stick in the functions:

@Override
public boolean onQueryTextSubmit(String myQuery) {
    // "myQuery" represents query as submitted.  Go ahead
    // and do your searchy stuff here
    return (false);
} /* on query text submit */


@Override
public boolean onQueryTextChange(String change)
{
    // "change" represents current text string as being typed
    return(false);
} /* on query text change */

That's all I wanted :)

Tab
  • 155
  • 9