Providing Search with SearchView (Android Development Patterns Ep 7)



SearchView is the standard interface for providing in app search for your Android app. SearchView is available via AppCompat and available back to Android …

source

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.

26 Replies to “Providing Search with SearchView (Android Development Patterns Ep 7)”

  1. Thanks, +Ian Lake, for this video. I'm just currently struggling with SearchView in my new app, and following the doc page on this topic I've come to some unsatisfactory dead-end.

    First, the doc page doesn't contain some details that you video does, so I can update my code to some degree (like MenuItemCompat, making the MainActivity a searcheable one and singleTop mode). Hope the doc pages will be updating faster…

    Second, my main problem was, and is, that according to SearchView doc page all you may do (with a Search Configuration) is launch another activity where you display a list of found items. But I believe the main pattern here would be do something about your main content within MainActivity, like scroll to the found item or marking visually the items that were found.

    And basically I see no option to gracefully step back to MainActivity from the Searchable activity to display the search results within the context of the main content.

  2. +Ian Lake – there appears to be some missing information to get this to work. The SearchView appears in my menu, and it appears when clicked. However, the SearchActivity is not delivered the search intent when the Search button is selected. I've tried adding android.app.default_searchable to my main Activity (and also to the application block) in AndroidManifest.xml, but still not receiving search intents. I'm not sure it is required (anymore? ever?) as you do not mention it here.

    StackOverflow is filled with people having similar problems, and many non-working suggestions are marked as the correct solution.

    Can you provide a sample project on Github showing that this works, or possibly a followup video on how to troubleshoot common errors with regards to this functionality? I now remember why I opted to build my own Search functionality years ago instead of using this built in capability.

  3. My goal is to create a search activity where users of my social app can search for and "friend" existing existing users. I was considering using a SearchView but it may be more simple to just use a EditText view with something like a RecyclerView to display my results. Every time the user types a character, my Cloud Endpoints backend will execute an API method that searches the GAE datastore for users that match that criteria and swap the data in the RecyclerView. Do you think I should still use a SearchView? What added benefits would I receive? I guess what I am trying to say is – I am not convinced a SearchView is worth all that trouble in my social app situation.

  4. @Tomislav Turcic

    <android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="@dimen/triple_height_toolbar"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    add these themes it will look like above vidoe

  5. Hi Android Developers,

    I have a query and it is kind of urgent. I want to know how to make the toolbar option which contains the searchview work for searching places in google map. I know to use a button and then code for it, but in toolbar the searchview has the magnifying glass symbol , how do i integrate it with the google map and use geocode.
    This is the code I want to implement:
    private void doSearch() {
    EditText location_field = (EditText) findViewById(R.id.edtsearch);
    String location = location_field.getText().toString();
    List addressList = null;
    if (location != null || !location.equals(“”)) ;
    {
    Geocoder geocoder = new Geocoder(this);
    {
    try {
    addressList = geocoder.getFromLocationName(location, 1);
    } catch (IOException e) {
    e.printStackTrace();
    }
    Address address = addressList.get(0);
    LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
    mMap.addMarker(new MarkerOptions().position(latLng).title(“Marker”));
    mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.getUiSettings().isCompassEnabled();
    mMap.getUiSettings().isZoomControlsEnabled();
    }

  6. Would be great if android comes up with a easier to use widget than current searchview/widget.
    Its much easier to program an edittext/button combination to do a search than to implement this feature…

  7. In the video you use the SearchView from the support library but the one in the official reference (urls in the description) use the default, outdated one. Are they still the recommended documentation for the searchview? Can I use the old one even though we are all using material design now?

  8. Why is it so complex? A simple EditText with a "addTextChangedListener" is so easy and fast. Why do I need to modify the manifest, then hook up a new activity and handle the query in there? The widget should be implementable in a single activity.

  9. Please I followed the tutorial on the android site for learning how to search let's say for pets name using the search menu just like we search our contacts on the phone for names. I tried searching for pets, the search button is now functional but it is doesn't search anything when I click it. Please I uploaded a link here of the whole app and how far I have gone.Please Could you help me check what I haven't done right that is not allowing d search button to search for the names. Meanwhile, everything is functional, the app doesn't crash at all.
    Here is the link:
    https://drive.google.com/file/d/0B_rCcU2ED5NUaWhlaEdEenFqdU0/view?usp=drivesdk

Leave a Reply