android - SearchView hints not showing for single character typed -


i'm working on android application written in scala uses android.support.v7.widget.searchview inside action bar that's overridden android.support.v7.widget.toolbar.

in app, need enable search suggestions searchview. so, every time detect query change, check see if suggestions need updated (code below). if suggestions need updated call made backend , android.database.matrixcursor created contains search suggestions , set on searchviews suggestions adapter (code below).

the problem i'm having search hints not show when typing single character. typing 2 or more characters in search box works perfectly.

i've tried android:searchsuggestthreshold set 0 , 1 in xml config , same result (like option being ignored): search hints showing multiple input characters, not showing single character.

am missing in config/initialisation of searchview? option other android:searchsuggestthreshold can set? i've spent last few hours on looking alternative options couldn't find any.

a possible solution see getting autocompletetextview backing searchview's input , setting threshold 1, it's ugly (hack-ish) solution autocompletetextview not exposed searchviews api.

does know elegant solution this?

thank you!

detecting search term changes:

//this gets called whenever changed in search box. "s" contains entire search term typed in search box def onquerytextchange(s: string): boolean = {   //this checks see if call should made backend update suggestions   searchsuggestioncontroller.query(s)    //return false we're not consuming event   false } 

updating search suggestions:

def updatesuggestions(suggestions: array[string]): unit = {   val cursor = new matrixcursor(array(basecolumns._id, searchmanager.suggest_column_text_1), suggestions.length)   for{     <- suggestions.indices     s = suggestions(i)   } cursor.addrow(array[anyref](i.tostring, s))    getactivity.runonuithread(() => {     searchsuggestionadapter.changecursor(cursor)     searchsuggestionadapter.notifydatasetchanged()   }) } 

menu searchview initialization:

override def oncreateoptionsmenu(menu: menu, inflater: menuinflater) = {     inflater.inflate(r.menu.menu_products, menu)     val searchmanager = getactivity.getsystemservice(context.search_service).asinstanceof[searchmanager]     val actionitem = menu.finditem(r.id.action_search)     searchview = menuitemcompat.getactionview(actionitem).asinstanceof[searchview]     searchview.setsearchableinfo(searchmanager.getsearchableinfo(getactivity.getcomponentname))     searchview.setsubmitbuttonenabled(false)     searchsuggestioncontroller.onsuggestionsprovided_=(updatesuggestions)     searchview setsuggestionsadapter searchsuggestionadapter     searchview.setonquerytextlistener(new searchview.onquerytextlistener() {        //...       //change listener detecting search changes presented above       //...     }   //...   //initialise other components    //... } 

searchable config:

<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android"     android:label="@string/app_name"     android:hint="@string/actionbar_products_search_hint"     android:searchsuggestthreshold="0"     android:searchsuggestselection=" ?"/> 

you must handle searchautocomplete object searchview object using, pragmatically set threshold 1.(if try set 0 become 1 implemented behind scenes) unfortunately wont work xml reason.

searchview.searchautocomplete msearchsrctextview = (searchview.searchautocomplete) searchview.findviewbyid(android.support.v7.appcompat.r.id.search_src_text); // show results 1 char msearchsrctextview.setthreshold(1); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -