Android 更改searchView阈值
我有一个小问题:我有一个使用SuggestionaAdapter的searchView。问题是searchView开始显示来自2个字符的结果。不过,我在代码中的searchable.xml+中将阈值设置为1,但它不起作用。这里的神奇之处在于,如果我将阈值设置为5,它就会起作用 Searchable.xml:Android 更改searchView阈值,android,xml,android-fragments,searchview,threshold,Android,Xml,Android Fragments,Searchview,Threshold,我有一个小问题:我有一个使用SuggestionaAdapter的searchView。问题是searchView开始显示来自2个字符的结果。不过,我在代码中的searchable.xml+中将阈值设置为1,但它不起作用。这里的神奇之处在于,如果我将阈值设置为5,它就会起作用 Searchable.xml: <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@s
<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>
其中我设置了自定义适配器:(调用:public boolean onQueryTextChange(String newText))
根据文档,您必须在可搜索文件中声明searchSuggestAutority:
android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider"
如果您确实想使用SuggestionAdapter提供数据,请不要在updateSearchResults中调用SetSuggestionAdapter,而要在onCreate中调用SetSuggestionAdapter,只需更新光标即可。
您还可以查看您可以将Appcompact活动与v7 Searchview一起使用。使用以下命令更改阈值
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
autoCompleteTextView.setThreshold(0);
尝试将
android:searchSuggestThreshold=“1”
更改为android:completionThreshold=“1”
我已经尝试过了,但在searchable.xml中我无法设置此参数。我也无法将此参数设置为布局文件中的searchView。我认为这个参数是用于AutocompleteTextView。。。
public void updateSearchResults() {
mSearchView.setSuggestionsAdapter(new CityListSearchResultAdapter(root.getContext(), mCursor));
}
android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider"
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
autoCompleteTextView.setThreshold(0);