arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 668 forks source link

setSearchText don't start search #303

Open PaolinoAngeletti opened 6 years ago

PaolinoAngeletti commented 6 years ago

If I try to set programmatically the text with setSearchText method, the search don't start and suggestions aren't showed. It'a bug or setSearchText isn't the right way?

kkl260 commented 4 years ago

I know this is old, but I had the same issue so I wanted to leave a response on how I fixed this in case anyone else comes by this issue.

I had the same issue when doing the voice search. I would voice search and setSearchText with my results, but it didn't do the search. So I pressed the enter button programmatically. Here is my code in Kotlin:

            Thread(Runnable {
                try {
                    val inst = Instrumentation()
                    inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER)
                } catch (e: InterruptedException) {
                }
            }).start()

This will press the enter button for you, starting the search. Obviously your search view would have to be in focus, setSearchText() should do that anyways, but if it doesn't you can add : search_view.setSearchFocused(true)