Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set SearchView threshold to zero

Tags:

android

I am using SearchView in android , i setting an adapter to search view, but suggestion popup box showing after one character, because i set Threshold on 1 ( it is not accept number less than 1 ), how can i set Threshold to Zero?
Like Google please, as you maybe know Google play does not have Threshold on application 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>
like image 246
Ali Hasanzade Avatar asked Apr 25 '26 08:04

Ali Hasanzade


1 Answers

Use Appcompact activity with v7 Searchview and set threshold as follows,

AutoCompleteTextView searchAutoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchAutoCompleteTextView.setThreshold(0);
like image 52
Parinda Rajapaksha Avatar answered Apr 26 '26 22:04

Parinda Rajapaksha