Search code examples
androidandroid-actionbarsearchview

Android insert listview with searchview results


I want to display a ListView with item results from a SearchView request like this:

enter image description here

I don't want to use ActionbarSherlock and I can not find any tutorial.


Solution

  • Use Custom Suggestions in the menu xml for the ActionBar

    <?xml version="1.0" encoding="utf-8"?>
    <searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_label"
        android:hint="@string/search_hint"
        android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider">
    </searchable>
    

    or create the autocompletetextview in the layout and add the Layout Inflator and set the setCustom

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
       LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(R.layout.yourlayout, null);
    
          actionBar.setCustomView(v);