Android APIs
public class

SearchFragment

extends Fragment
java.lang.Object
   ↳ android.app.Fragment
     ↳ android.support.v17.leanback.app.SearchFragment

Class Overview

A fragment to handle searches. An application will supply an implementation of the SearchFragment.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 BrowseFragment.

Note: Your application will need to request android.permission.RECORD_AUDIO.

Summary

Nested Classes
interface SearchFragment.SearchResultProvider Search API to be provided by the application. 
[Expand]
Inherited Constants
From interface android.content.ComponentCallbacks2
Public Constructors
SearchFragment()
Public Methods
static Bundle createArgs(Bundle args, String query, String title)
static Bundle createArgs(Bundle args, String query)
void displayCompletions(List<String> completions)
Display the completions shown by the IME.
Drawable getBadgeDrawable()
Returns the badge drawable in the search bar.
String getTitle()
Returns the title set in the search bar.
static SearchFragment newInstance(String query)
Create a search fragment with a given search query.
void onCreate(Bundle savedInstanceState)
Called to do initial creation of a fragment.
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view.
void onPause()
Called when the Fragment is no longer resumed.
void onResume()
Called when the fragment is visible to the user and actively running.
void onStart()
Called when the Fragment is visible to the user.
void setBadgeDrawable(Drawable drawable)
Sets the badge drawable that will be shown inside the search bar next to the title.
void setOnItemClickedListener(OnItemClickedListener listener)
Sets an item clicked listener for the results.
void setOnItemSelectedListener(OnItemSelectedListener listener)
Sets an item selection listener for the results.
void setSearchResultProvider(SearchFragment.SearchResultProvider searchResultProvider)
Set the search provider that is responsible for returning results for the search query.
void setTitle(String title)
Sets the title string to be be shown in an empty search bar.
[Expand]
Inherited Methods
From class android.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2
From interface android.view.View.OnCreateContextMenuListener

Public Constructors

public SearchFragment ()

Public Methods

public static Bundle createArgs (Bundle args, String query, String title)

public static Bundle createArgs (Bundle args, String query)

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

public void displayCompletions (List<String> completions)

Display 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 A list of completions to show in the IME. Setting to null or empty will clear the list.

public Drawable getBadgeDrawable ()

Returns the badge drawable in the search bar.

public String getTitle ()

Returns the title set in the search bar.

public static SearchFragment newInstance (String query)

Create 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 The search query to begin with.
Returns
  • A new SearchFragment.

public void onCreate (Bundle savedInstanceState)

Called to do initial creation of a fragment. This is called after onAttach(Activity) and before onCreateView(LayoutInflater, ViewGroup, Bundle).

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, see onActivityCreated(Bundle).

Parameters
savedInstanceState If the fragment is being re-created from a previous saved state, this is the state.

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called to have the fragment instantiate its user interface view. This is optional, and non-graphical fragments can return null (which is the default implementation). This will be called between onCreate(Bundle) and onActivityCreated(Bundle).

If you return a View from here, you will later be called in onDestroyView() when the view is being released.

Parameters
inflater The LayoutInflater object that can be used to inflate any views in the fragment,
container 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 If non-null, this fragment is being re-constructed from a previous saved state as given here.
Returns
  • Return the View for the fragment's UI, or null.

public void onPause ()

Called when the Fragment is no longer resumed. This is generally tied to Activity.onPause of the containing Activity's lifecycle.

public void onResume ()

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.

public void onStart ()

Called when the Fragment is visible to the user. This is generally tied to Activity.onStart of the containing Activity's lifecycle.

public void setBadgeDrawable (Drawable drawable)

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

public void setOnItemClickedListener (OnItemClickedListener listener)

Sets an item clicked listener for the results.

Parameters
listener The item clicked listener to be invoked when an item in the search results is clicked.

public void setOnItemSelectedListener (OnItemSelectedListener listener)

Sets an item selection listener for the results.

Parameters
listener The item selection listener to be invoked when an item in the search results is selected.

public void setSearchResultProvider (SearchFragment.SearchResultProvider searchResultProvider)

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

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".