SearchView


public class SearchView
extends LinearLayout implements CollapsibleActionView

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.LinearLayout
         ↳ android.widget.SearchView


A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. Shows a list of query suggestions or results, if available, and allows the user to pick a suggestion or result to launch into.

When the SearchView is used in an ActionBar as an action view for a collapsible menu item, it needs to be set to iconified by default using setIconifiedByDefault(true). This is the default, so nothing needs to be done.

If you want the search field to always be visible, then call setIconifiedByDefault(false).

Developer Guides

For information about using SearchView, read the Search developer guide.

Summary

Nested classes

interface SearchView.OnCloseListener

 

interface SearchView.OnQueryTextListener

Callbacks for changes to the query text. 

interface SearchView.OnSuggestionListener

Callback interface for selection events on suggestions. 

XML attributes

android:iconifiedByDefault The default state of the SearchView. 
android:imeOptions The IME options to set on the query text field. 
android:inputType The input type to set on the query text field. 
android:maxWidth An optional maximum width of the SearchView. 
android:queryHint An optional query hint string to be displayed in the empty query field. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

SearchView(Context context)
SearchView(Context context, AttributeSet attrs)
SearchView(Context context, AttributeSet attrs, int defStyleAttr)
SearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

int getImeOptions()

Returns the IME options set on the query text field.

int getInputType()

Returns the input type set on the query text field.

int getMaxWidth()

Gets the specified maximum width in pixels, if set.

CharSequence getQuery()

Returns the query string currently in the text field.

CharSequence getQueryHint()

Returns the hint text that will be displayed in the query text field.

CursorAdapter getSuggestionsAdapter()

Returns the adapter used for suggestions, if any.

boolean isIconfiedByDefault()

This method was deprecated in API level 29. use isIconifiedByDefault()

boolean isIconified()

Returns the current iconified state of the SearchView.

boolean isIconifiedByDefault()

Returns the default iconified state of the search field.

boolean isQueryRefinementEnabled()

Returns whether query refinement is enabled for all items or only specific ones.

boolean isSubmitButtonEnabled()

Returns whether the submit button is enabled when necessary or never displayed.

void onActionViewCollapsed()

Called when this view is collapsed as an action view.

void onActionViewExpanded()

Called when this view is expanded as an action view.

boolean onKeyDown(int keyCode, KeyEvent event)

Handles the key down event for dealing with action keys.

void onWindowFocusChanged(boolean hasWindowFocus)

Called when the window containing this view gains or loses focus.

void setIconified(boolean iconify)

Iconifies or expands the SearchView.

void setIconifiedByDefault(boolean iconified)

Sets the default or resting state of the search field.

void setImeOptions(int imeOptions)

Sets the IME options on the query text field.

void setInputType(int inputType)

Sets the input type on the query text field.

void setMaxWidth(int maxpixels)

Makes the view at most this many pixels wide

void setOnCloseListener(SearchView.OnCloseListener listener)

Sets a listener to inform when the user closes the SearchView.

void setOnQueryTextFocusChangeListener(View.OnFocusChangeListener listener)

Sets a listener to inform when the focus of the query text field changes.

void setOnQueryTextListener(SearchView.OnQueryTextListener listener)

Sets a listener for user actions within the SearchView.

void setOnSearchClickListener(View.OnClickListener listener)

Sets a listener to inform when the search button is pressed.

void setOnSuggestionListener(SearchView.OnSuggestionListener listener)

Sets a listener to inform when a suggestion is focused or clicked.

void setQuery(CharSequence query, boolean submit)

Sets a query string in the text field and optionally submits the query as well.

void setQueryHint(CharSequence hint)

Sets the hint text to display in the query text field.

void setQueryRefinementEnabled(boolean enable)

Specifies if a query refinement button should be displayed alongside each suggestion or if it should depend on the flags set in the individual items retrieved from the suggestions provider.

void setSearchableInfo(SearchableInfo searchable)

Sets the SearchableInfo for this SearchView.

void setSubmitButtonEnabled(boolean enabled)

Enables showing a submit button when the query is non-empty.

void setSuggestionsAdapter(CursorAdapter adapter)

You can set a custom adapter if you wish.

Protected methods

void onDetachedFromWindow()

This is called when the view is detached from a window.

void onLayout(boolean changed, int left, int top, int right, int bottom)

Called from layout when this view should assign a size and position to each of its children.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

void onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

Inherited methods

XML attributes

android:iconifiedByDefault

The default state of the SearchView. If true, it will be iconified when not in use and expanded when clicked.

May be a boolean value, such as "true" or "false".

Related methods:

android:imeOptions

The IME options to set on the query text field.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
actionDone6The action key performs a "done" operation, closing the soft input method. Corresponds to EditorInfo.IME_ACTION_DONE.
actionGo2The action key performs a "go" operation to take the user to the target of the text they typed. Typically used, for example, when entering a URL. Corresponds to EditorInfo.IME_ACTION_GO.
actionNext5The action key performs a "next" operation, taking the user to the next field that will accept text. Corresponds to EditorInfo.IME_ACTION_NEXT.
actionNone1This editor has no action associated with it. Corresponds to EditorInfo.IME_ACTION_NONE.
actionPrevious7The action key performs a "previous" operation, taking the user to the previous field that will accept text. Corresponds to EditorInfo.IME_ACTION_PREVIOUS.
actionSearch3The action key performs a "search" operation, taking the user to the results of searching for the text the have typed (in whatever context is appropriate). Corresponds to EditorInfo.IME_ACTION_SEARCH.
actionSend4The action key performs a "send" operation, delivering the text to its target. This is typically used when composing a message. Corresponds to EditorInfo.IME_ACTION_SEND.
actionUnspecified0There is no specific action associated with this editor, let the editor come up with its own if it can. Corresponds to EditorInfo.IME_NULL.
flagForceAscii80000000Used to request that the IME should be capable of inputting ASCII characters. The intention of this flag is to ensure that the user can type Roman alphabet characters in a TextView used for, typically, account ID or password input. It is expected that IMEs normally are able to input ASCII even without being told so (such IMEs already respect this flag in a sense), but there could be some cases they aren't when, for instance, only non-ASCII input languages like Arabic, Greek, Hebrew, Russian are enabled in the IME. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it. However, it is strongly recommended for IME authors to respect this flag especially when their IME could end up with a state that has only non-ASCII input languages enabled.

Corresponds to EditorInfo.IME_FLAG_FORCE_ASCII.

flagNavigateNext8000000Used to specify that there is something interesting that a forward navigation can focus on. This is like using actionNext, except allows the IME to be multiline (with an enter key) as well as provide forward navigation. Note that some IMEs may not be able to do this, especially when running on a small screen where there is little space. In that case it does not need to present a UI for this option. Like actionNext, if the user selects the IME's facility to forward navigate, this will show up in the application at InputConnection.performEditorAction(int).

Corresponds to EditorInfo.IME_FLAG_NAVIGATE_NEXT.

flagNavigatePrevious4000000Like flagNavigateNext, but specifies there is something interesting that a backward navigation can focus on. If the user selects the IME's facility to backward navigate, this will show up in the application as an actionPrevious at InputConnection.performEditorAction(int).

Corresponds to EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS.

flagNoAccessoryAction20000000Used in conjunction with a custom action, this indicates that the action should not be available as an accessory button when the input method is full-screen. Note that by setting this flag, there can be cases where the action is simply never available to the user. Setting this generally means that you think showing text being edited is more important than the action you have supplied.

Corresponds to EditorInfo.IME_FLAG_NO_ACCESSORY_ACTION.

flagNoEnterAction40000000Used in conjunction with a custom action, this indicates that the action should not be available in-line as a replacement for the "enter" key. Typically this is because the action has such a significant impact or is not recoverable enough that accidentally hitting it should be avoided, such as sending a message. Note that TextView will automatically set this flag for you on multi-line text views.

Corresponds to EditorInfo.IME_FLAG_NO_ENTER_ACTION.

flagNoExtractUi10000000Used to specify that the IME does not need to show its extracted text UI. For input methods that may be fullscreen, often when in landscape mode, this allows them to be smaller and let part of the application be shown behind. Though there will likely be limited access to the application available from the user, it can make the experience of a (mostly) fullscreen IME less jarring. Note that when this flag is specified the IME may not be set up to be able to display text, so it should only be used in situations where this is not needed.

Corresponds to EditorInfo.IME_FLAG_NO_EXTRACT_UI.

flagNoFullscreen2000000Used to request that the IME never go into fullscreen mode. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it.

Corresponds to EditorInfo.IME_FLAG_NO_FULLSCREEN.

flagNoPersonalizedLearning1000000Used to request that the IME should not update any personalized data such as typing history and personalized language model based on what the user typed on this text editing object. Typical use cases are:
  • When the application is in a special mode, where user's activities are expected to be not recorded in the application's history. Some web browsers and chat applications may have this kind of modes.
  • When storing typing history does not make much sense. Specifying this flag in typing games may help to avoid typing history from being filled up with words that the user is less likely to type in their daily life. Another example is that when the application already knows that the expected input is not a valid word (e.g. a promotion code that is not a valid word in any natural language).

Applications need to be aware that the flag is not a guarantee, and some IMEs may not respect it.

normal0There are no special semantics associated with this editor.

Related methods:

android:inputType

The input type to set on the query text field.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
date14For entering a date. Corresponds to InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE.
datetime4For entering a date and time. Corresponds to InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_NORMAL.
none0There is no content type. The text is not editable.
number2A numeric only field. Corresponds to InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL.
numberDecimal2002Can be combined with number and its other options to allow a decimal (fractional) number. Corresponds to InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL.
numberPassword12A numeric password field. Corresponds to InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD.
numberSigned1002Can be combined with number and its other options to allow a signed number. Corresponds to InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED.
phone3For entering a phone number. Corresponds to InputType.TYPE_CLASS_PHONE.
text1Just plain old text. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL.
textAutoComplete10001Can be combined with text and its variations to specify that this field will be doing its own auto-completion and talking with the input method appropriately. Corresponds to InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE.
textAutoCorrect8001Can be combined with text and its variations to request auto-correction of text being input. Corresponds to InputType.TYPE_TEXT_FLAG_AUTO_CORRECT.
textCapCharacters1001Can be combined with text and its variations to request capitalization of all characters. Corresponds to InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS.
textCapSentences4001Can be combined with text and its variations to request capitalization of the first character of every sentence. Corresponds to InputType.TYPE_TEXT_FLAG_CAP_SENTENCES.
textCapWords2001Can be combined with text and its variations to request capitalization of the first character of every word. Corresponds to InputType.TYPE_TEXT_FLAG_CAP_WORDS.
textEmailAddress21Text that will be used as an e-mail address. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS.
textEmailSubject31Text that is being supplied as the subject of an e-mail. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT.
textEnableTextConversionSuggestions100001Can be combined with text and its variations to indicate that if there is extra information, the IME should provide TextAttribute. Corresponds to InputType.TYPE_TEXT_FLAG_ENABLE_TEXT_CONVERSION_SUGGESTIONS.
textFilterb1Text that is filtering some other data. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER.
textImeMultiLine40001Can be combined with text and its variations to indicate that though the regular text view should not be multiple lines, the IME should provide multiple lines if it can. Corresponds to InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE.
textLongMessage51Text that is the content of a long message. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE.
textMultiLine20001Can be combined with text and its variations to allow multiple lines of text in the field. If this flag is not set, the text field will be constrained to a single line. Corresponds to InputType.TYPE_TEXT_FLAG_MULTI_LINE. Note: If this flag is not set and the text field doesn't have max length limit, the framework automatically set maximum length of the characters to 5000 for the performance reasons.
textNoSuggestions80001Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds to InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS.
textPassword81Text that is a password. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD.
textPersonName61Text that is the name of a person. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME.
textPhoneticc1Text that is for phonetic pronunciation, such as a phonetic name field in a contact entry. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PHONETIC.
textPostalAddress71Text that is being supplied as a postal mailing address. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS.
textShortMessage41Text that is the content of a short message. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE.
textUri11Text that will be used as a URI. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI.
textVisiblePassword91Text that is a password that should be visible. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD.
textWebEditTexta1Text that is being supplied as text in a web form. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT.
textWebEmailAddressd1Text that will be used as an e-mail address on a web form. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS.
textWebPassworde1Text that will be used as a password on a web form. Corresponds to InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD.
time24For entering a time. Corresponds to InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME.

Related methods:

android:maxWidth

An optional maximum width of the SearchView.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Related methods:

android:queryHint

An optional query hint string to be displayed in the empty query field.

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

Related methods:

Public constructors

SearchView

Added in API level 11
public SearchView (Context context)

Parameters
context Context

SearchView

Added in API level 11
public SearchView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

SearchView

Added in API level 21
public SearchView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

SearchView

Added in API level 21
public SearchView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

getAccessibilityClassName

Added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getImeOptions

Added in API level 16
public int getImeOptions ()

Returns the IME options set on the query text field.

Related XML Attributes:

Returns
int the ime options

getInputType

Added in API level 16
public int getInputType ()

Returns the input type set on the query text field.

Related XML Attributes:

Returns
int the input type

getMaxWidth

Added in API level 16
public int getMaxWidth ()

Gets the specified maximum width in pixels, if set. Returns zero if no maximum width was specified.

Related XML Attributes:

Returns
int the maximum width of the view

getQuery

Added in API level 11
public CharSequence getQuery ()

Returns the query string currently in the text field.

Returns
CharSequence the query string

getQueryHint

Added in API level 16
public CharSequence getQueryHint ()

Returns the hint text that will be displayed in the query text field.

The displayed query hint is chosen in the following order:

  1. Non-null value set with setQueryHint(java.lang.CharSequence)
  2. Value specified in XML using android:queryHint
  3. Valid string resource ID exposed by the SearchableInfo via SearchableInfo#getHintId()
  4. Default hint provided by the theme against which the view was inflated

Related XML Attributes:

Returns
CharSequence the displayed query hint text, or null if none set

getSuggestionsAdapter

Added in API level 11
public CursorAdapter getSuggestionsAdapter ()

Returns the adapter used for suggestions, if any.

Returns
CursorAdapter the suggestions adapter

isIconfiedByDefault

Added in API level 11
Deprecated in API level 29
public boolean isIconfiedByDefault ()

This method was deprecated in API level 29.
use isIconifiedByDefault()

Returns the default iconified state of the search field.

Related XML Attributes:

Returns
boolean

isIconified

Added in API level 11
public boolean isIconified ()

Returns the current iconified state of the SearchView.

Returns
boolean true if the SearchView is currently iconified, false if the search field is fully visible.

isIconifiedByDefault

Added in API level 29
public boolean isIconifiedByDefault ()

Returns the default iconified state of the search field.

Related XML Attributes:

Returns
boolean

isQueryRefinementEnabled

Added in API level 11
public boolean isQueryRefinementEnabled ()

Returns whether query refinement is enabled for all items or only specific ones.

Returns
boolean true if enabled for all items, false otherwise.

isSubmitButtonEnabled

Added in API level 11
public boolean isSubmitButtonEnabled ()

Returns whether the submit button is enabled when necessary or never displayed.

Returns
boolean whether the submit button is enabled automatically when necessary

onActionViewCollapsed

Added in API level 14
public void onActionViewCollapsed ()

Called when this view is collapsed as an action view. See MenuItem#collapseActionView().

onActionViewExpanded

Added in API level 14
public void onActionViewExpanded ()

Called when this view is expanded as an action view. See MenuItem#expandActionView().

onKeyDown

Added in API level 11
public boolean onKeyDown (int keyCode, 
                KeyEvent event)

Handles the key down event for dealing with action keys.

Parameters
keyCode int: This is the keycode of the typed key, and is the same value as found in the KeyEvent parameter.

event KeyEvent: The complete event record for the typed key

Returns
boolean true if the event was handled here, or false if not.

onWindowFocusChanged

Added in API level 11
public void onWindowFocusChanged (boolean hasWindowFocus)

Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.

Parameters
hasWindowFocus boolean: True if the window containing this view now has focus, false otherwise.

setIconified

Added in API level 11
public void setIconified (boolean iconify)

Iconifies or expands the SearchView. Any query text is cleared when iconified. This is a temporary state and does not override the default iconified state set by setIconifiedByDefault(boolean). If the default state is iconified, then a false here will only be valid until the user closes the field. And if the default state is expanded, then a true here will only clear the text field and not close it.

Parameters
iconify boolean: a true value will collapse the SearchView to an icon, while a false will expand it.

setIconifiedByDefault

Added in API level 11
public void setIconifiedByDefault (boolean iconified)

Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.

The default value is true.

Related XML Attributes:

Parameters
iconified boolean: whether the search field should be iconified by default

setImeOptions

Added in API level 14
public void setImeOptions (int imeOptions)

Sets the IME options on the query text field.

Related XML Attributes:

Parameters
imeOptions int: the options to set on the query text field

setInputType

Added in API level 14
public void setInputType (int inputType)

Sets the input type on the query text field.

Related XML Attributes:

Parameters
inputType int: the input type to set on the query text field

setMaxWidth

Added in API level 11
public void setMaxWidth (int maxpixels)

Makes the view at most this many pixels wide

Related XML Attributes:

Parameters
maxpixels int

setOnCloseListener

Added in API level 11
public void setOnCloseListener (SearchView.OnCloseListener listener)

Sets a listener to inform when the user closes the SearchView.

Parameters
listener SearchView.OnCloseListener: the listener to call when the user closes the SearchView.

setOnQueryTextFocusChangeListener

Added in API level 11
public void setOnQueryTextFocusChangeListener (View.OnFocusChangeListener listener)

Sets a listener to inform when the focus of the query text field changes.

Parameters
listener View.OnFocusChangeListener: the listener to inform of focus changes.

setOnQueryTextListener

Added in API level 11
public void setOnQueryTextListener (SearchView.OnQueryTextListener listener)

Sets a listener for user actions within the SearchView.

Parameters
listener SearchView.OnQueryTextListener: the listener object that receives callbacks when the user performs actions in the SearchView such as clicking on buttons or typing a query.

setOnSearchClickListener

Added in API level 11
public void setOnSearchClickListener (View.OnClickListener listener)

Sets a listener to inform when the search button is pressed. This is only relevant when the text field is not visible by default. Calling setIconified(false) can also cause this listener to be informed.

Parameters
listener View.OnClickListener: the listener to inform when the search button is clicked or the text field is programmatically de-iconified.

setOnSuggestionListener

Added in API level 11
public void setOnSuggestionListener (SearchView.OnSuggestionListener listener)

Sets a listener to inform when a suggestion is focused or clicked.

Parameters
listener SearchView.OnSuggestionListener: the listener to inform of suggestion selection events.

setQuery

Added in API level 11
public void setQuery (CharSequence query, 
                boolean submit)

Sets a query string in the text field and optionally submits the query as well.

Parameters
query CharSequence: the query string. This replaces any query text already present in the text field.

submit boolean: whether to submit the query right now or only update the contents of text field.

setQueryHint

Added in API level 11
public void setQueryHint (CharSequence hint)

Sets the hint text to display in the query text field. This overrides any hint specified in the SearchableInfo.

This value may be specified as an empty string to prevent any query hint from being displayed.

Related XML Attributes:

Parameters
hint CharSequence: the hint text to display or null to clear

setQueryRefinementEnabled

Added in API level 11
public void setQueryRefinementEnabled (boolean enable)

Specifies if a query refinement button should be displayed alongside each suggestion or if it should depend on the flags set in the individual items retrieved from the suggestions provider. Clicking on the query refinement button will replace the text in the query text field with the text from the suggestion. This flag only takes effect if a SearchableInfo has been specified with setSearchableInfo(android.app.SearchableInfo) and not when using a custom adapter.

Parameters
enable boolean: true if all items should have a query refinement button, false if only those items that have a query refinement flag set should have the button.

setSearchableInfo

Added in API level 11
public void setSearchableInfo (SearchableInfo searchable)

Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used to display labels, hints, suggestions, create intents for launching search results screens and controlling other affordances such as a voice button.

Parameters
searchable SearchableInfo: a SearchableInfo can be retrieved from the SearchManager, for a specific activity or a global search provider.

setSubmitButtonEnabled

Added in API level 11
public void setSubmitButtonEnabled (boolean enabled)

Enables showing a submit button when the query is non-empty. In cases where the SearchView is being used to filter the contents of the current activity and doesn't launch a separate results activity, then the submit button should be disabled.

Parameters
enabled boolean: true to show a submit button for submitting queries, false if a submit button is not required.

setSuggestionsAdapter

Added in API level 11
public void setSuggestionsAdapter (CursorAdapter adapter)

You can set a custom adapter if you wish. Otherwise the default adapter is used to display the suggestions from the suggestions provider associated with the SearchableInfo.

Parameters
adapter CursorAdapter

Protected methods

onDetachedFromWindow

Added in API level 11
protected void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
If you override this method you must call through to the superclass implementation.

onLayout

Added in API level 11
protected void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed boolean: This is a new size or position for this view

left int: Left position, relative to parent

top int: Top position, relative to parent

right int: Right position, relative to parent

bottom int: Bottom position, relative to parent

onMeasure

Added in API level 11
protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

onRestoreInstanceState

Added in API level 11
protected void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.
If you override this method you must call through to the superclass implementation.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onSaveInstanceState

Added in API level 11
protected Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
If you override this method you must call through to the superclass implementation.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.