I added a search widget to my action bar and would like to handle the autocomplete function. After writing more than three letters, he should execute an http request to my web API, which will return a json result and should display suggestions of search widgets. But in the documentation there is a case with content providers. How can I organize the autofill function?
Added search in the xml file menu:
<item android:id="@+id/search" android:icon="@drawable/ic_search_white_24dp" android:title="Search" [namespace]:showAsAction="always" [namespace]:actionViewClass="android.widget.SearchView" />
Matches search customizable configuration using SearchView:
public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.navigation, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); return super.onCreateOptionsMenu(menu); }
Search feature added:
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search_hint" android:searchSuggestAuthority="com.my.domain.searchable_activity" />
And ultimately added an empty responsible activity.
android search autocomplete
Tigran vardanyan
source share