Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SearchView voice listener

Tags:

java

android

I would like to know if it is possible to set voice listener on my searchView, like the suggestion listener: http://developer.android.com/reference/android/support/v7/widget/SearchView.OnSuggestionListener.html

I want to overwrite the default behavior. I don't want to launch another activity. I just want to get the recorded voice as a string and use it.

like image 931
Radoslav Yordanov Avatar asked May 02 '15 20:05

Radoslav Yordanov


People also ask

How to implement SearchView in Android?

SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.

What is onQueryTextSubmit()?

public abstract boolean onQueryTextSubmit (String query) Called when the user submits the query. This could be due to a key press on the keyboard or due to pressing a submit button. The listener can override the standard behavior by returning true to indicate that it has handled the submit request.

How to add search box in Android studio?

Add the Search View to the App Bar To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.


2 Answers

I read what you ask for, but Why don't you want to use an activity? Just in case this can help you, you should take a look at these if you havn't till now:

Andriod developers: http://developer.android.com/guide/topics/search/search-dialog.html#VoiceSearch

Examples:

http://www.codeproject.com/Articles/821839/A-Beginners-Guide-to-Working-With-Speech-and-Audio http://www.truiton.com/2014/06/android-speech-recognition-without-dialog-custom-activity/

Hope it helps, yakobom

like image 167
yakobom Avatar answered Oct 08 '22 12:10

yakobom


To show the microphone icon you need to add a search configuration and set it to your SearchView. See this question and my answer here https://stackoverflow.com/a/48527608/114549

like image 1
aaronvargas Avatar answered Oct 08 '22 11:10

aaronvargas