SearchFragment

Added in 1.1.0
Deprecated in 1.1.0

public class SearchFragment extends 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 methods

static Bundle
createArgs(Bundle args, String query)
static Bundle
createArgs(Bundle args, String query, String title)
void
displayCompletions(CompletionInfo[] completions)

Displays the completions shown by the IME.

void

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.

static SearchFragment

Creates a search fragment with a given search query.

void
onCreate(Bundle savedInstanceState)

This method is deprecated.

@Nullable View
onCreateView(
    LayoutInflater inflater,
    @Nullable ViewGroup container,
    Bundle savedInstanceState
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

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

void

Sets an item clicked listener for the results.

void

Sets an item selection listener for the results.

void

Sets background color of not-listening state search orb.

void

Sets background color of listening state search orb.

void
setSearchQuery(Intent intent, boolean submit)

Sets the text of the search query based on the EXTRA_RESULTS in the given intent, and optionally submit the query.

void
setSearchQuery(String query, boolean submit)

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

void

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

void

This method is deprecated.

Launching voice recognition activity is no longer supported.

void

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

void

Starts speech recognition.

Inherited Constants

From android.content.ComponentCallbacks2
static final int
static final int
static final int
static final int
static final int
static final int
static final int

Inherited methods

From android.app.Fragment
void
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

This method is deprecated.

final boolean

This method is deprecated.

final Activity

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

final Bundle

This method is deprecated.

final FragmentManager

This method is deprecated.

Context

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final FragmentManager

This method is deprecated.

final Object

This method is deprecated.

final int

This method is deprecated.

final LayoutInflater

This method is deprecated.

LoaderManager

This method is deprecated.

final Fragment

This method is deprecated.

Transition

This method is deprecated.

final Resources

This method is deprecated.

final boolean

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final String
getString(int resId)

This method is deprecated.

final String

This method is deprecated.

final Fragment

This method is deprecated.

final int

This method is deprecated.

final CharSequence
getText(int resId)

This method is deprecated.

boolean

This method is deprecated.

View

This method is deprecated.

final int

This method is deprecated.

static Fragment
instantiate(Context context, String fname)

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

void
onActivityCreated(Bundle savedInstanceState)

This method is deprecated.

void
onActivityResult(int requestCode, int resultCode, Intent data)

This method is deprecated.

void
onAttach(Context context)

This method is deprecated.

void
onAttachFragment(Fragment childFragment)

This method is deprecated.

void

This method is deprecated.

boolean

This method is deprecated.

Animator
onCreateAnimator(int transit, boolean enter, int nextAnim)

This method is deprecated.

void
onCreateContextMenu(
    ContextMenu menu,
    View v,
    ContextMenu.ContextMenuInfo menuInfo
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

LayoutInflater
onGetLayoutInflater(Bundle savedInstanceState)

This method is deprecated.

void
onHiddenChanged(boolean hidden)

This method is deprecated.

void
onInflate(AttributeSet attrs, Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

void
onMultiWindowModeChanged(
    boolean isInMultiWindowMode,
    Configuration newConfig
)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void
onPictureInPictureModeChanged(
    boolean isInPictureInPictureMode,
    Configuration newConfig
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onTrimMemory(int level)

This method is deprecated.

void
onViewCreated(View view, Bundle savedInstanceState)

This method is deprecated.

void
onViewStateRestored(Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

final void
requestPermissions(String[] permissions, int requestCode)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
setHasOptionsMenu(boolean hasMenu)

This method is deprecated.

void

This method is deprecated.

void
setMenuVisibility(boolean menuVisible)

This method is deprecated.

void

This method is deprecated.

void
setRetainInstance(boolean retain)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
setTargetFragment(Fragment fragment, int requestCode)

This method is deprecated.

void
setUserVisibleHint(boolean isVisibleToUser)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void
startActivityForResult(Intent intent, int requestCode)

This method is deprecated.

void
startIntentSenderForResult(
    IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    Bundle options
)

This method is deprecated.

void

This method is deprecated.

String

This method is deprecated.

void

This method is deprecated.

Public constructors

SearchFragment

Added in 1.1.0
Deprecated in 1.1.0
public SearchFragment()

Public methods

createArgs

Added in 1.1.0
Deprecated in 1.1.0
public static Bundle createArgs(Bundle args, String query)
Parameters
Bundle args

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
public static Bundle createArgs(Bundle args, String query, String title)

displayCompletions

Added in 1.1.0
Deprecated in 1.1.0
public void displayCompletions(CompletionInfo[] completions)

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
CompletionInfo[] completions

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
public void displayCompletions(List<String> completions)

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
List<String> completions

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
public Drawable getBadgeDrawable()

Returns the badge drawable in the search bar.

getRecognizerIntent

Added in 1.1.0
Deprecated in 1.1.0
public Intent getRecognizerIntent()

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
public RowsFragment getRowsFragment()

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
public String getTitle()

Returns the title set in the search bar.

newInstance

Added in 1.1.0
Deprecated in 1.1.0
public static SearchFragment newInstance(String query)

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
String query

The search query to begin with.

Returns
SearchFragment

A new SearchFragment.

onCreate

Added in 1.1.0
Deprecated in 1.1.0
public void onCreate(Bundle savedInstanceState)

onCreateView

Added in 1.1.0
Deprecated in 1.1.0
public @Nullable View onCreateView(
    LayoutInflater inflater,
    @Nullable ViewGroup container,
    Bundle savedInstanceState
)

onDestroy

Added in 1.1.0
Deprecated in 1.1.0
public void onDestroy()

onDestroyView

Added in 1.1.0
Deprecated in 1.1.0
public void onDestroyView()

onPause

Added in 1.1.0
Deprecated in 1.1.0
public void onPause()

onRequestPermissionsResult

Added in 1.1.0
Deprecated in 1.1.0
public void onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)

onResume

Added in 1.1.0
Deprecated in 1.1.0
public void onResume()

onStart

Added in 1.1.0
Deprecated in 1.1.0
public void onStart()

setBadgeDrawable

Added in 1.1.0
Deprecated in 1.1.0
public void setBadgeDrawable(Drawable drawable)

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
public void setOnItemViewClickedListener(OnItemViewClickedListener listener)

Sets an item clicked listener for the results.

Parameters
OnItemViewClickedListener listener

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
public void setOnItemViewSelectedListener(OnItemViewSelectedListener listener)

Sets an item selection listener for the results.

Parameters
OnItemViewSelectedListener listener

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
public void setSearchAffordanceColors(SearchOrbView.Colors colors)

Sets background color of not-listening state search orb.

Parameters
SearchOrbView.Colors colors

SearchOrbView.Colors.

setSearchAffordanceColorsInListening

Added in 1.1.0
Deprecated in 1.1.0
public void setSearchAffordanceColorsInListening(SearchOrbView.Colors colors)

Sets background color of listening state search orb.

Parameters
SearchOrbView.Colors colors

SearchOrbView.Colors.

setSearchQuery

Added in 1.1.0
Deprecated in 1.1.0
public void setSearchQuery(Intent intent, boolean submit)

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.

boolean submit

Whether to submit the query.

setSearchQuery

Added in 1.1.0
Deprecated in 1.1.0
public void setSearchQuery(String query, boolean submit)

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
String query

The search query to set.

boolean submit

Whether to submit the query.

setSearchResultProvider

Added in 1.1.0
Deprecated in 1.1.0
public void setSearchResultProvider(
    SearchFragment.SearchResultProvider searchResultProvider
)

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
public void setSpeechRecognitionCallback(SpeechRecognitionCallback callback)

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
public void setTitle(String title)

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
public void startRecognition()

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.