Change searchView threshold
I have a little problem: I have a searchView which works with the suggestionAdapter. The problem is that the searchView start to display results from 2 characters. I have however set the threshold to 1 in the searchable.xml + in the code but it doesn't works.The magic here is if I set the threshold to 5 it works...
Searchable.xml:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/city_list_search"
android:hint="@string/city_list_search"
android:searchSuggestThreshold="1">
</searchable>
Manifest.xml:
<activity
android:name=".activities.HomeActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.SEARCH" />
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</intent-filter>
</activity>
My fragment where I also set the threshold to 1:
AutoCompleteTextView search_text = (AutoCompleteTextView) mSearchView.findViewById(mSearchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
search_text.setThreshold(1);
mSearchView.setIconifiedByDefault(false);
mSearchView.setSearchableInfo(mSearchManager.getSearchableInfo(getActivity().getComponentName()));
Where I set the custom adapter: (called in : public boolean onQueryTextChange(String newText))
public void updateSearchResults() {
mSearchView.setSuggestionsAdapter(new CityListSearchResultAdapter(root.getContext(), mCursor));
}
According to documentation, you have to declare the searchSuggestAutority in your searchable :
android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider"
http://developer.android.com/guide/topics/search/adding-custom-suggestions.html
if you really want to use suggestionsAdapter to provide data, don't call setSuggestionsAdapter in updateSearchResults but in onCreate, just update your cursor. You can also have a look to https://gist.github.com/slightfoot/5514856
You can use Appcompact activity with v7 Searchview. Use as follows to change the threshold,
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
autoCompleteTextView.setThreshold(0);
链接地址: http://www.djcxy.com/p/16594.html
上一篇: searchView必须包含在MenuItem中吗?
下一篇: 更改searchView阈值