将SearchView阈值设置为零

时间:2015-03-03 16:32:58

标签: android

我在android中使用SearchView,我设置了一个适配器来搜索视图,但是建议弹出框显示一个字符后,因为我将阈值设置为1(它不是接受数小于1),怎么能我将阈值设置为零? 请跟Google一样,因为您可能知道Google Play在申请SearchView上没有阈值。

@Override
public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) 
{
    inflater.inflate(R.menu.main, menu);
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnQueryTextListener(this); 
    searchView.setOnSuggestionListener(this);
}

@Override
public boolean onQueryTextChange(final String arg0)
{
    searchView.setSuggestionsAdapter(locationSearchAdapater);
}

searchable.xml

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

    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"

    android:searchSuggestThreshold="1"
    android:completionThreshold = "1"  >


</searchable>

1 个答案:

答案 0 :(得分:2)

在v7 Searchview中使用Appcompact活动并设置阈值,如下所示,

AutoCompleteTextView searchAutoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchAutoCompleteTextView.setThreshold(0);