com.actionbarsherlock.widget
Class SearchView

java.lang.Object
  extended by android.view.View
      extended by android.view.ViewGroup
          extended by android.widget.LinearLayout
              extended by com.actionbarsherlock.widget.SearchView
All Implemented Interfaces:
android.graphics.drawable.Drawable.Callback, android.view.accessibility.AccessibilityEventSource, android.view.KeyEvent.Callback, android.view.ViewManager, android.view.ViewParent, CollapsibleActionView

public class SearchView
extends android.widget.LinearLayout
implements CollapsibleActionView

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.

See Also:
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW

Nested Class Summary
static interface SearchView.OnCloseListener
           
static interface SearchView.OnQueryTextListener
          Callbacks for changes to the query text.
static interface SearchView.OnSuggestionListener
          Callback interface for selection events on suggestions.
static class SearchView.SearchAutoComplete
          Local subclass for AutoCompleteTextView.
 
Nested classes/interfaces inherited from class android.widget.LinearLayout
android.widget.LinearLayout.LayoutParams
 
Nested classes/interfaces inherited from class android.view.ViewGroup
android.view.ViewGroup.MarginLayoutParams, android.view.ViewGroup.OnHierarchyChangeListener
 
Nested classes/interfaces inherited from class android.view.View
android.view.View.AccessibilityDelegate, android.view.View.BaseSavedState, android.view.View.DragShadowBuilder, android.view.View.MeasureSpec, android.view.View.OnAttachStateChangeListener, android.view.View.OnClickListener, android.view.View.OnCreateContextMenuListener, android.view.View.OnDragListener, android.view.View.OnFocusChangeListener, android.view.View.OnGenericMotionListener, android.view.View.OnHoverListener, android.view.View.OnKeyListener, android.view.View.OnLayoutChangeListener, android.view.View.OnLongClickListener, android.view.View.OnSystemUiVisibilityChangeListener, android.view.View.OnTouchListener
 
Field Summary
 
Fields inherited from class android.widget.LinearLayout
HORIZONTAL, SHOW_DIVIDER_BEGINNING, SHOW_DIVIDER_END, SHOW_DIVIDER_MIDDLE, SHOW_DIVIDER_NONE, VERTICAL
 
Fields inherited from class android.view.ViewGroup
CLIP_TO_PADDING_MASK, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
 
Fields inherited from class android.view.View
ALPHA, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_RESOLVED_DEFAULT, TRANSLATION_X, TRANSLATION_Y, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y
 
Constructor Summary
SearchView(android.content.Context context)
           
SearchView(android.content.Context context, android.util.AttributeSet attrs)
           
 
Method Summary
 void clearFocus()
           
 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()
          Gets the hint text to display in the query text field.
 android.support.v4.widget.CursorAdapter getSuggestionsAdapter()
          Returns the adapter used for suggestions, if any.
 boolean isIconfiedByDefault()
          Returns the default iconified state of the search field.
 boolean isIconified()
          Returns the current iconified state of the SearchView.
 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.
protected  void onDetachedFromWindow()
           
 void onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
           
 void onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
           
 boolean onKeyDown(int keyCode, android.view.KeyEvent event)
          Handles the key down event for dealing with action keys.
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           
 void onWindowFocusChanged(boolean hasWindowFocus)
           
 boolean requestFocus(int direction, android.graphics.Rect previouslyFocusedRect)
           
 void setAppSearchData(android.os.Bundle appSearchData)
          Sets the APP_DATA for legacy SearchDialog use.
 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(android.view.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(android.view.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(android.app.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(android.support.v4.widget.CursorAdapter adapter)
          You can set a custom adapter if you wish.
 
Methods inherited from class android.widget.LinearLayout
checkLayoutParams, generateDefaultLayoutParams, generateLayoutParams, generateLayoutParams, getBaseline, getBaselineAlignedChildIndex, getDividerDrawable, getDividerPadding, getOrientation, getShowDividers, getWeightSum, isBaselineAligned, isMeasureWithLargestChildEnabled, onDraw, onLayout, setBaselineAligned, setBaselineAlignedChildIndex, setDividerDrawable, setDividerPadding, setGravity, setHorizontalGravity, setMeasureWithLargestChildEnabled, setOrientation, setShowDividers, setVerticalGravity, setWeightSum, shouldDelayChildPressedState
 
Methods inherited from class android.view.ViewGroup
addChildrenForAccessibility, addFocusables, addStatesFromChildren, addTouchables, addView, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, childDrawableStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchFreezeSelfOnly, dispatchGenericFocusedEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchSystemUiVisibilityChanged, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableStateChanged, drawChild, endViewTransition, findFocus, findViewsWithText, fitSystemWindows, focusableViewAvailable, focusSearch, gatherTransparentRegion, getChildAt, getChildCount, getChildDrawingOrder, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutTransition, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, isMotionEventSplittingEnabled, jumpDrawablesToCurrentState, layout, measureChild, measureChildren, measureChildWithMargins, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onCreateDrawableState, onInterceptHoverEvent, onInterceptTouchEvent, onRequestFocusInDescendants, onRequestSendAccessibilityEvent, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestSendAccessibilityEvent, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPadding, setPersistentDrawingCache, setStaticTransformationsEnabled, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, updateViewLayout
 
Methods inherited from class android.view.View
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelLongPress, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAnimation, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchGenericMotionEvent, dispatchPopulateAccessibilityEvent, draw, findViewById, findViewWithTag, focusSearch, forceLayout, getAccessibilityNodeProvider, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getImportantForAccessibility, getKeepScreenOn, getKeyDispatcherState, getLayerType, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOverScrollMode, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hasOnClickListeners, hasOverlappingRendering, hasTransientState, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDisplayHint, onDragEvent, onDrawScrollBars, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onGenericMotionEvent, onHoverChanged, onHoverEvent, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onOverScrolled, onPopulateAccessibilityEvent, onRestoreInstanceState, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSetAlpha, onSizeChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, overScrollBy, performAccessibilityAction, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setKeepScreenOn, setLayerType, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, startActionMode, startAnimation, startDrag, unscheduleDrawable, unscheduleDrawable, verifyDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface android.view.ViewParent
createContextMenu, getParent, getParentForAccessibility, isLayoutRequested, requestFitSystemWindows, requestLayout
 

Constructor Detail

SearchView

public SearchView(android.content.Context context)

SearchView

public SearchView(android.content.Context context,
                  android.util.AttributeSet attrs)
Method Detail

setSearchableInfo

public void setSearchableInfo(android.app.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 - a SearchableInfo can be retrieved from the SearchManager, for a specific activity or a global search provider.

setAppSearchData

public void setAppSearchData(android.os.Bundle appSearchData)
Sets the APP_DATA for legacy SearchDialog use.

Parameters:
appSearchData - bundle provided by the app when launching the search dialog

setImeOptions

public void setImeOptions(int imeOptions)
Sets the IME options on the query text field.

Parameters:
imeOptions - the options to set on the query text field
See Also:
TextView.setImeOptions(int)

getImeOptions

public int getImeOptions()
Returns the IME options set on the query text field.

Returns:
the ime options
See Also:
TextView.setImeOptions(int)

setInputType

public void setInputType(int inputType)
Sets the input type on the query text field.

Parameters:
inputType - the input type to set on the query text field
See Also:
TextView.setInputType(int)

getInputType

public int getInputType()
Returns the input type set on the query text field.

Returns:
the input type

requestFocus

public boolean requestFocus(int direction,
                            android.graphics.Rect previouslyFocusedRect)
Overrides:
requestFocus in class android.view.ViewGroup

clearFocus

public void clearFocus()
Overrides:
clearFocus in class android.view.ViewGroup

setOnQueryTextListener

public void setOnQueryTextListener(SearchView.OnQueryTextListener listener)
Sets a listener for user actions within the SearchView.

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

setOnCloseListener

public void setOnCloseListener(SearchView.OnCloseListener listener)
Sets a listener to inform when the user closes the SearchView.

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

setOnQueryTextFocusChangeListener

public void setOnQueryTextFocusChangeListener(android.view.View.OnFocusChangeListener listener)
Sets a listener to inform when the focus of the query text field changes.

Parameters:
listener - the listener to inform of focus changes.

setOnSuggestionListener

public void setOnSuggestionListener(SearchView.OnSuggestionListener listener)
Sets a listener to inform when a suggestion is focused or clicked.

Parameters:
listener - the listener to inform of suggestion selection events.

setOnSearchClickListener

public void setOnSearchClickListener(android.view.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 - the listener to inform when the search button is clicked or the text field is programmatically de-iconified.

getQuery

public CharSequence getQuery()
Returns the query string currently in the text field.

Returns:
the query string

setQuery

public void setQuery(CharSequence query,
                     boolean submit)
Sets a query string in the text field and optionally submits the query as well.

Parameters:
query - the query string. This replaces any query text already present in the text field.
submit - whether to submit the query right now or only update the contents of text field.

setQueryHint

public void setQueryHint(CharSequence hint)
Sets the hint text to display in the query text field. This overrides any hint specified in the SearchableInfo.

Parameters:
hint - the hint text to display

getQueryHint

public CharSequence getQueryHint()
Gets the hint text to display in the query text field.

Returns:
the query hint text, if specified, null otherwise.

setIconifiedByDefault

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.

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

isIconfiedByDefault

public boolean isIconfiedByDefault()
Returns the default iconified state of the search field.

Returns:

setIconified

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 - a true value will collapse the SearchView to an icon, while a false will expand it.

isIconified

public boolean isIconified()
Returns the current iconified state of the SearchView.

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

setSubmitButtonEnabled

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 - true to show a submit button for submitting queries, false if a submit button is not required.

isSubmitButtonEnabled

public boolean isSubmitButtonEnabled()
Returns whether the submit button is enabled when necessary or never displayed.

Returns:
whether the submit button is enabled automatically when necessary

setQueryRefinementEnabled

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(SearchableInfo) and not when using a custom adapter.

Parameters:
enable - 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.
See Also:
SearchManager.SUGGEST_COLUMN_FLAGS, SearchManager.FLAG_QUERY_REFINEMENT

isQueryRefinementEnabled

public boolean isQueryRefinementEnabled()
Returns whether query refinement is enabled for all items or only specific ones.

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

setSuggestionsAdapter

public void setSuggestionsAdapter(android.support.v4.widget.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.

See Also:
setSearchableInfo(SearchableInfo)

getSuggestionsAdapter

public android.support.v4.widget.CursorAdapter getSuggestionsAdapter()
Returns the adapter used for suggestions, if any.

Returns:
the suggestions adapter

setMaxWidth

public void setMaxWidth(int maxpixels)
Makes the view at most this many pixels wide


getMaxWidth

public int getMaxWidth()
Gets the specified maximum width in pixels, if set. Returns zero if no maximum width was specified.

Returns:
the maximum width of the view

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Overrides:
onMeasure in class android.widget.LinearLayout

onDetachedFromWindow

protected void onDetachedFromWindow()
Overrides:
onDetachedFromWindow in class android.view.View

onKeyDown

public boolean onKeyDown(int keyCode,
                         android.view.KeyEvent event)
Handles the key down event for dealing with action keys.

Specified by:
onKeyDown in interface android.view.KeyEvent.Callback
Overrides:
onKeyDown in class android.view.View
Parameters:
keyCode - This is the keycode of the typed key, and is the same value as found in the KeyEvent parameter.
event - The complete event record for the typed key
Returns:
true if the event was handled here, or false if not.

onWindowFocusChanged

public void onWindowFocusChanged(boolean hasWindowFocus)
Overrides:
onWindowFocusChanged in class android.view.View

onActionViewCollapsed

public void onActionViewCollapsed()
Called when this view is collapsed as an action view. See MenuItem.collapseActionView().

Specified by:
onActionViewCollapsed in interface CollapsibleActionView

onActionViewExpanded

public void onActionViewExpanded()
Called when this view is expanded as an action view. See MenuItem.expandActionView().

Specified by:
onActionViewExpanded in interface CollapsibleActionView

onInitializeAccessibilityEvent

public void onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
Overrides:
onInitializeAccessibilityEvent in class android.widget.LinearLayout

onInitializeAccessibilityNodeInfo

public void onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
Overrides:
onInitializeAccessibilityNodeInfo in class android.widget.LinearLayout


Copyright © 2012-2013. All Rights Reserved.