atsu
atsu

Reputation: 81

android SearchView widget: how to display the voice query text to the search text box?

I cannot believe that I'm not seeing more discussions about this issue. Am I missing something that obvious?

I have my activity with SearchView widget with Voice enabled. This a singleTop instance, so that same activity will be able to catch the search intent.

When user inputs using voice, I would like to display the query text to the user for any correction (if needed) before the actual search happens.

In my onNewIntent() method, I handle the search intent to retrive the query text from the voice and update the search text box.

However, as soon as I set the text box with the query text, a new search intent is triggered with the SearchViews Text. And the same is received by my onNewIntent().

This is going in an infinite loop.

I tried to set up the SearchView's OnQueryTextListener, hoping the listener will catch the search text from the text box directly. It did, however, that didn't stop new search intents to be triggered.

I'm about to give up the SearchView. Considering I wanted to have the voice and suggestion features, I'm hoping someone can suggest me a solution for this problem.

Upvotes: 3

Views: 1037

Answers (1)

atsu
atsu

Reputation: 81

Fixed. The problem was the call to display the query text to the text box, searchView.setQuery(query, false) takes two parameters, and the second parameter indicates if the text needs to be submitted after placing in the box. I must have copied the code from an example and didn't pay attention to second parameter. It was 'true' but should be 'false' in this case.

Upvotes: 2

Related Questions