SearchSupportFragment
class SearchSupportFragment : Fragment
A fragment to handle searches. An application will supply an implementation of the SearchResultProvider interface to handle the search and return an ObjectAdapter containing the results. The results are rendered into a RowsSupportFragment, in the same way that they are in a BrowseSupportFragment.
A SpeechRecognizer object will be created for which your application will need to declare android.permission.RECORD_AUDIO in AndroidManifest file. If app's target version is >= 23 and the device version is >= 23, a permission dialog will show first time using speech recognition. 0 will be used as requestCode in requestPermissions() call. setSpeechRecognitionCallback is deprecated.
Speech recognition is automatically started when fragment is created, but not when fragment is restored from an instance state. Activity may manually call startRecognition, typically in onNewIntent().
Summary
Nested types |
|---|
|
Search API to be provided by the application. |
Public constructors |
|---|
Public functions |
|
|---|---|
java-static Bundle! |
createArgs(args: Bundle!, query: String!) |
java-static Bundle! |
createArgs(args: Bundle!, query: String!, title: String!) |
Unit |
displayCompletions(completions: Array<CompletionInfo!>!)Displays the completions shown by the IME. |
Unit |
displayCompletions(completions: (Mutable)List<String!>!)Displays the completions shown by the IME. |
Drawable! |
Returns the badge drawable in the search bar. |
Intent! |
Returns an intent that can be used to request speech recognition. |
RowsSupportFragment! |
Returns RowsSupportFragment that shows result rows. |
String! |
getTitle()Returns the title set in the search bar. |
java-static SearchSupportFragment! |
newInstance(query: String!)Creates a search fragment with a given search query. |
Unit |
Called to do initial creation of a fragment. |
View? |
onCreateView(Called to have the fragment instantiate its user interface view. |
Unit |
Called when the fragment is no longer in use. |
Unit |
Called when the view previously created by |
Unit |
onPause()Called when the Fragment is no longer resumed. |
Unit |
onRequestPermissionsResult(This function is deprecated. This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an |
Unit |
onResume()Called when the fragment is visible to the user and actively running. |
Unit |
onStart()Called when the Fragment is visible to the user. |
Unit |
setBadgeDrawable(drawable: Drawable!)Sets the badge drawable that will be shown inside the search bar next to the title. |
Unit |
Sets an item clicked listener for the results. |
Unit |
Sets an item selection listener for the results. |
Unit |
Sets background color of not-listening state search orb. |
Unit |
Sets background color of listening state search orb. |
Unit |
setSearchQuery(intent: Intent!, submit: Boolean)Sets the text of the search query based on the |
Unit |
setSearchQuery(query: String!, submit: Boolean)Sets the text of the search query and optionally submits the query. |
Unit |
setSearchResultProvider(Sets the search provider that is responsible for returning results for the search query. |
Unit |
This function is deprecated. Launching voice recognition activity is no longer supported. |
Unit |
Sets the title string to be be shown in an empty search bar. |
Unit |
Starts speech recognition. |
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
Public functions
createArgs
java-static fun createArgs(args: Bundle!, query: String!, title: String!): Bundle!
displayCompletions
fun displayCompletions(completions: Array<CompletionInfo!>!): Unit
Displays the completions shown by the IME. An application may provide a list of query completions that the system will show in the IME.
| Parameters | |
|---|---|
completions: Array<CompletionInfo!>! |
A list of completions to show in the IME. Setting to null or empty will clear the list. |
displayCompletions
fun displayCompletions(completions: (Mutable)List<String!>!): Unit
Displays the completions shown by the IME. An application may provide a list of query completions that the system will show in the IME.
getBadgeDrawable
fun getBadgeDrawable(): Drawable!
Returns the badge drawable in the search bar.
getRecognizerIntent
fun getRecognizerIntent(): Intent!
Returns an intent that can be used to request speech recognition. Built from the base ACTION_RECOGNIZE_SPEECH plus extras:
EXTRA_LANGUAGE_MODELset toLANGUAGE_MODEL_FREE_FORMEXTRA_PARTIAL_RESULTSset to trueEXTRA_PROMPTset to the search bar hint text
setSearchQuery.getRowsSupportFragment
fun getRowsSupportFragment(): RowsSupportFragment!
Returns RowsSupportFragment that shows result rows. RowsSupportFragment is initialized after SearchSupportFragment.onCreateView().
| Returns | |
|---|---|
RowsSupportFragment! |
RowsSupportFragment that shows result rows. |
newInstance
java-static fun newInstance(query: String!): SearchSupportFragment!
Creates a search fragment with a given search query.
You should only use this if you need to start the search fragment with a pre-filled query.
| Parameters | |
|---|---|
query: String! |
The search query to begin with. |
| Returns | |
|---|---|
SearchSupportFragment! |
A new SearchSupportFragment. |
onCreate
fun onCreate(savedInstanceState: Bundle!): Unit
Called to do initial creation of a fragment. This is called after onAttach and before onCreateView.
Note that this can be called while the fragment's activity is still in the process of being created. As such, you can not rely on things like the activity's content view hierarchy being initialized at this point. If you want to do work once the activity itself is created, add a androidx.lifecycle.LifecycleObserver on the activity's Lifecycle, removing it when it receives the CREATED callback.
Any restored child fragments will be created before the base Fragment.onCreate method returns.
| Parameters | |
|---|---|
savedInstanceState: Bundle! |
If the fragment is being re-created from a previous saved state, this is the state. |
onCreateView
fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View?
Called to have the fragment instantiate its user interface view. This is optional, and non-graphical fragments can return null. This will be called between onCreate and onViewCreated.
A default View can be returned by calling Fragment in your constructor. Otherwise, this method returns null.
It is recommended to only inflate the layout in this method and move logic that operates on the returned View to onViewCreated.
If you return a View from here, you will later be called in onDestroyView when the view is being released.
| Parameters | |
|---|---|
inflater: LayoutInflater |
The LayoutInflater object that can be used to inflate any views in the fragment, |
container: ViewGroup? |
If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view. |
savedInstanceState: Bundle? |
If non-null, this fragment is being re-constructed from a previous saved state as given here. |
| Returns | |
|---|---|
View? |
Return the View for the fragment's UI, or null. |
onDestroy
fun onDestroy(): Unit
Called when the fragment is no longer in use. This is called after onStop and before onDetach.
onDestroyView
fun onDestroyView(): Unit
Called when the view previously created by onCreateView has been detached from the fragment. The next time the fragment needs to be displayed, a new view will be created. This is called after onStop and before onDestroy. It is called regardless of whether onCreateView returned a non-null view. Internally it is called after the view's state has been saved but before it has been removed from its parent.
onPause
fun onPause(): Unit
Called when the Fragment is no longer resumed. This is generally tied to Activity.onPause of the containing Activity's lifecycle.
onRequestPermissionsResult
fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String!>!,
grantResults: IntArray<Int>!
): Unit
Callback for the result from requesting permissions. This method is invoked for every call on requestPermissions.
Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.
| Parameters | |
|---|---|
requestCode: Int |
The request code passed in |
permissions: Array<String!>! |
The requested permissions. Never null. |
grantResults: IntArray<Int>! |
The grant results for the corresponding permissions which is either |
| See also | |
|---|---|
requestPermissions |
onResume
fun onResume(): Unit
Called when the fragment is visible to the user and actively running. This is generally tied to Activity.onResume of the containing Activity's lifecycle.
onStart
fun onStart(): Unit
Called when the Fragment is visible to the user. This is generally tied to Activity.onStart of the containing Activity's lifecycle.
setBadgeDrawable
fun setBadgeDrawable(drawable: Drawable!): Unit
Sets the badge drawable that will be shown inside the search bar next to the title.
setOnItemViewClickedListener
fun setOnItemViewClickedListener(listener: OnItemViewClickedListener!): Unit
Sets an item clicked listener for the results.
| Parameters | |
|---|---|
listener: OnItemViewClickedListener! |
The item clicked listener to be invoked when an item in the search results is clicked. |
setOnItemViewSelectedListener
fun setOnItemViewSelectedListener(listener: OnItemViewSelectedListener!): Unit
Sets an item selection listener for the results.
| Parameters | |
|---|---|
listener: OnItemViewSelectedListener! |
The item selection listener to be invoked when an item in the search results is selected. |
setSearchAffordanceColors
fun setSearchAffordanceColors(colors: SearchOrbView.Colors!): Unit
Sets background color of not-listening state search orb.
| Parameters | |
|---|---|
colors: SearchOrbView.Colors! |
SearchOrbView.Colors. |
setSearchAffordanceColorsInListening
fun setSearchAffordanceColorsInListening(colors: SearchOrbView.Colors!): Unit
Sets background color of listening state search orb.
| Parameters | |
|---|---|
colors: SearchOrbView.Colors! |
SearchOrbView.Colors. |
setSearchQuery
fun setSearchQuery(intent: Intent!, submit: Boolean): Unit
Sets the text of the search query based on the EXTRA_RESULTS in the given intent, and optionally submit the query. If more than one result is present in the results list, the first will be used.
setSearchQuery
fun setSearchQuery(query: String!, submit: Boolean): Unit
Sets the text of the search query and optionally submits the query. Either onQueryTextChange or onQueryTextSubmit will be called on the provider if it is set.
setSearchResultProvider
fun setSearchResultProvider(
searchResultProvider: SearchSupportFragment.SearchResultProvider!
): Unit
Sets the search provider that is responsible for returning results for the search query.
funsetSpeechRecognitionCallback(callback: SpeechRecognitionCallback!): Unit
Sets this callback to have the fragment pass speech recognition requests to the activity rather than using a SpeechRecognizer object.
setTitle
fun setTitle(title: String!): Unit
Sets the title string to be be shown in an empty search bar. The title may be placed in a call-to-action, such as "Search title" or "Speak to search title".
startRecognition
fun startRecognition(): Unit
Starts speech recognition. Typical use case is that activity receives onNewIntent() call when user clicks a MIC button. Note that SearchSupportFragment automatically starts speech recognition at first time created, there is no need to call startRecognition() when fragment is created.