SearchFragment

Added in 1.1.0
Deprecated in 1.1.0

class SearchFragment : 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 RowsFragment, in the same way that they are in a .

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

Displays the completions shown by the IME.

Unit

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.

RowsFragment!

Returns RowsFragment that shows result rows.

String!

Returns the title set in the search bar.

java-static SearchFragment!

Creates a search fragment with a given search query.

Unit
onCreate(savedInstanceState: Bundle!)

This function is deprecated.

View?
onCreateView(
    inflater: LayoutInflater!,
    container: ViewGroup?,
    savedInstanceState: Bundle!
)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String!>!,
    grantResults: IntArray!
)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

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 EXTRA_RESULTS in the given intent, and optionally submit the query.

Unit
setSearchQuery(query: String!, submit: Boolean)

Sets the text of the search query and optionally submits the query.

Unit

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
setTitle(title: String!)

Sets the title string to be be shown in an empty search bar.

Unit

Starts speech recognition.

Inherited functions

From android.app.Fragment
Unit
dump(
    prefix: String!,
    fd: FileDescriptor!,
    writer: PrintWriter!,
    args: Array<String!>!
)

This function is deprecated.

Boolean
equals(o: Any!)

This function is deprecated.

Activity!

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Bundle!

This function is deprecated.

FragmentManager!

This function is deprecated.

Context!

This function is deprecated.

Transition!

This function is deprecated.

Transition!

This function is deprecated.

FragmentManager!

This function is deprecated.

Any!

This function is deprecated.

Int

This function is deprecated.

LayoutInflater!

This function is deprecated.

LoaderManager!

This function is deprecated.

Fragment!

This function is deprecated.

Transition!

This function is deprecated.

Resources!

This function is deprecated.

Boolean

This function is deprecated.

Transition!

This function is deprecated.

Transition!

This function is deprecated.

Transition!

This function is deprecated.

String!
getString(resId: Int)

This function is deprecated.

String!

This function is deprecated.

Fragment!

This function is deprecated.

Int

This function is deprecated.

CharSequence!
getText(resId: Int)

This function is deprecated.

Boolean

This function is deprecated.

View!

This function is deprecated.

Int

This function is deprecated.

java-static Fragment!
instantiate(context: Context!, fname: String!)

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Unit
onActivityCreated(savedInstanceState: Bundle!)

This function is deprecated.

Unit
onActivityResult(requestCode: Int, resultCode: Int, data: Intent!)

This function is deprecated.

Unit
onAttach(context: Context!)

This function is deprecated.

Unit
onAttachFragment(childFragment: Fragment!)

This function is deprecated.

Unit

This function is deprecated.

Boolean

This function is deprecated.

Animator!
onCreateAnimator(transit: Int, enter: Boolean, nextAnim: Int)

This function is deprecated.

Unit
onCreateContextMenu(
    menu: ContextMenu!,
    v: View!,
    menuInfo: ContextMenu.ContextMenuInfo!
)

This function is deprecated.

Unit
onCreateOptionsMenu(menu: Menu!, inflater: MenuInflater!)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

LayoutInflater!
onGetLayoutInflater(savedInstanceState: Bundle!)

This function is deprecated.

Unit

This function is deprecated.

Unit
onInflate(attrs: AttributeSet!, savedInstanceState: Bundle!)

This function is deprecated.

Unit

This function is deprecated.

Unit
onMultiWindowModeChanged(
    isInMultiWindowMode: Boolean,
    newConfig: Configuration!
)

This function is deprecated.

Boolean

This function is deprecated.

Unit

This function is deprecated.

Unit
onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration!
)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
onTrimMemory(level: Int)

This function is deprecated.

Unit
onViewCreated(view: View!, savedInstanceState: Bundle!)

This function is deprecated.

Unit
onViewStateRestored(savedInstanceState: Bundle!)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
requestPermissions(permissions: Array<String!>!, requestCode: Int)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
setMenuVisibility(menuVisible: Boolean)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
setTargetFragment(fragment: Fragment!, requestCode: Int)

This function is deprecated.

Unit
setUserVisibleHint(isVisibleToUser: Boolean)

This function is deprecated.

Boolean

This function is deprecated.

Unit

This function is deprecated.

Unit
startActivityForResult(intent: Intent!, requestCode: Int)

This function is deprecated.

Unit
startIntentSenderForResult(
    intent: IntentSender!,
    requestCode: Int,
    fillInIntent: Intent!,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle!
)

This function is deprecated.

Unit

This function is deprecated.

String!

This function is deprecated.

Unit

This function is deprecated.

Public constructors

SearchFragment

Added in 1.1.0
Deprecated in 1.1.0
SearchFragment()

Public functions

createArgs

Added in 1.1.0
Deprecated in 1.1.0
java-static fun createArgs(args: Bundle!, query: String!): Bundle!
Parameters
args: Bundle!

Bundle to use for the arguments, if null a new Bundle will be created.

createArgs

Added in 1.1.0
Deprecated in 1.1.0
java-static fun createArgs(args: Bundle!, query: String!, title: String!): Bundle!

displayCompletions

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
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.

Parameters
completions: (Mutable)List<String!>!

A list of completions to show in the IME. Setting to null or empty will clear the list.

getBadgeDrawable

Added in 1.1.0
Deprecated in 1.1.0
fun getBadgeDrawable(): Drawable!

Returns the badge drawable in the search bar.

getRecognizerIntent

Added in 1.1.0
Deprecated in 1.1.0
fun getRecognizerIntent(): Intent!

Returns an intent that can be used to request speech recognition. Built from the base ACTION_RECOGNIZE_SPEECH plus extras:

For handling the intent returned from the service, see setSearchQuery.

getRowsFragment

Added in 1.1.0
Deprecated in 1.1.0
fun getRowsFragment(): RowsFragment!

Returns RowsFragment that shows result rows. RowsFragment is initialized after SearchFragment.onCreateView().

Returns
RowsFragment!

RowsFragment that shows result rows.

getTitle

Added in 1.1.0
Deprecated in 1.1.0
fun getTitle(): String!

Returns the title set in the search bar.

newInstance

Added in 1.1.0
Deprecated in 1.1.0
java-static fun newInstance(query: String!): SearchFragment!

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
SearchFragment!

A new SearchFragment.

onCreate

Added in 1.1.0
Deprecated in 1.1.0
fun onCreate(savedInstanceState: Bundle!): Unit

onCreateView

Added in 1.1.0
Deprecated in 1.1.0
fun onCreateView(
    inflater: LayoutInflater!,
    container: ViewGroup?,
    savedInstanceState: Bundle!
): View?

onDestroy

Added in 1.1.0
Deprecated in 1.1.0
fun onDestroy(): Unit

onDestroyView

Added in 1.1.0
Deprecated in 1.1.0
fun onDestroyView(): Unit

onPause

Added in 1.1.0
Deprecated in 1.1.0
fun onPause(): Unit

onRequestPermissionsResult

Added in 1.1.0
Deprecated in 1.1.0
fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String!>!,
    grantResults: IntArray!
): Unit

onResume

Added in 1.1.0
Deprecated in 1.1.0
fun onResume(): Unit

onStart

Added in 1.1.0
Deprecated in 1.1.0
fun onStart(): Unit

setBadgeDrawable

Added in 1.1.0
Deprecated in 1.1.0
fun setBadgeDrawable(drawable: Drawable!): Unit

Sets the badge drawable that will be shown inside the search bar next to the title.

setOnItemViewClickedListener

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
fun setSearchAffordanceColors(colors: SearchOrbView.Colors!): Unit

Sets background color of not-listening state search orb.

Parameters
colors: SearchOrbView.Colors!

SearchOrbView.Colors.

setSearchAffordanceColorsInListening

Added in 1.1.0
Deprecated in 1.1.0
fun setSearchAffordanceColorsInListening(colors: SearchOrbView.Colors!): Unit

Sets background color of listening state search orb.

Parameters
colors: SearchOrbView.Colors!

SearchOrbView.Colors.

setSearchQuery

Added in 1.1.0
Deprecated in 1.1.0
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.

Parameters
intent: Intent!

Intent received from a speech recognition service.

submit: Boolean

Whether to submit the query.

setSearchQuery

Added in 1.1.0
Deprecated in 1.1.0
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.

Parameters
query: String!

The search query to set.

submit: Boolean

Whether to submit the query.

setSearchResultProvider

Added in 1.1.0
Deprecated in 1.1.0
fun setSearchResultProvider(
    searchResultProvider: SearchFragment.SearchResultProvider!
): Unit

Sets the search provider that is responsible for returning results for the search query.

setSpeechRecognitionCallback

Added in 1.1.0
Deprecated in 1.1.0
fun setSpeechRecognitionCallback(callback: SpeechRecognitionCallback!): Unit

Sets this callback to have the fragment pass speech recognition requests to the activity rather than using a SpeechRecognizer object.

setTitle

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
fun startRecognition(): Unit

Starts speech recognition. Typical use case is that activity receives onNewIntent() call when user clicks a MIC button. Note that SearchFragment automatically starts speech recognition at first time created, there is no need to call startRecognition() when fragment is created.