FileDocCategorySizeDatePackage
SearchViewCompat.javaAPI DocAndroid 5.1 API18891Thu Mar 12 22:22:56 GMT 2015android.support.v4.widget

SearchViewCompat

public class SearchViewCompat extends Object
Helper for accessing features in {@link android.widget.SearchView} introduced after API level 4 in a backwards compatible fashion.

Fields Summary
private static final SearchViewCompatImpl
IMPL
Constructors Summary
private SearchViewCompat(android.content.Context context)

        if (Build.VERSION.SDK_INT >= 14) { // ICS
            IMPL = new SearchViewCompatIcsImpl();
        } else if (Build.VERSION.SDK_INT >= 11) { // Honeycomb
            IMPL = new SearchViewCompatHoneycombImpl();
        } else {
            IMPL = new SearchViewCompatStubImpl();
        }
    
        /* Hide constructor */
    
Methods Summary
public static java.lang.CharSequencegetQuery(android.view.View searchView)
Returns the query string currently in the text field.

param
searchView The SearchView to operate on.
return
the query string

        return IMPL.getQuery(searchView);
    
public static booleanisIconified(android.view.View searchView)
Returns the current iconified state of the SearchView.

param
searchView The SearchView to operate on.
return
true if the SearchView is currently iconified, false if the search field is fully visible.

        return IMPL.isIconified(searchView);
    
public static booleanisQueryRefinementEnabled(android.view.View searchView)
Returns whether query refinement is enabled for all items or only specific ones.

param
searchView The SearchView to operate on.
return
true if enabled for all items, false otherwise.

        return IMPL.isQueryRefinementEnabled(searchView);
    
public static booleanisSubmitButtonEnabled(android.view.View searchView)
Returns whether the submit button is enabled when necessary or never displayed.

param
searchView The SearchView to operate on.
return
whether the submit button is enabled automatically when necessary

        return IMPL.isSubmitButtonEnabled(searchView);
    
public static android.view.ViewnewSearchView(android.content.Context context)
Creates a new SearchView.

param
context The Context the view is running in.
return
A SearchView instance if the class is present on the current platform, null otherwise.

        return IMPL.newSearchView(context);
    
public static voidsetIconified(android.view.View searchView, 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.

param
searchView The SearchView to operate on.
param
iconify a true value will collapse the SearchView to an icon, while a false will expand it.

        IMPL.setIconified(searchView, iconify);
    
public static voidsetImeOptions(android.view.View searchView, int imeOptions)
Sets the IME options on the query text field. This is a no-op if called on pre-{@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} platforms.

see
TextView#setImeOptions(int)
param
searchView The SearchView to operate on.
param
imeOptions the options to set on the query text field

        IMPL.setImeOptions(searchView, imeOptions);
    
public static voidsetInputType(android.view.View searchView, int inputType)
Sets the input type on the query text field. This is a no-op if called on pre-{@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH} platforms.

see
TextView#setInputType(int)
param
searchView The SearchView to operate on.
param
inputType the input type to set on the query text field

        IMPL.setInputType(searchView, inputType);
    
public static voidsetMaxWidth(android.view.View searchView, int maxpixels)
Makes the view at most this many pixels wide

param
searchView The SearchView to operate on.

        IMPL.setMaxWidth(searchView, maxpixels);
    
public static voidsetOnCloseListener(android.view.View searchView, android.support.v4.widget.SearchViewCompat$OnCloseListenerCompat listener)
Sets a listener to inform when the user closes the SearchView.

param
searchView The SearchView in which to register the listener.
param
listener the listener to call when the user closes the SearchView.

        IMPL.setOnCloseListener(searchView, listener.mListener);
    
public static voidsetOnQueryTextListener(android.view.View searchView, android.support.v4.widget.SearchViewCompat$OnQueryTextListenerCompat listener)
Sets a listener for user actions within the SearchView.

param
searchView The SearchView in which to register the listener.
param
listener the listener object that receives callbacks when the user performs actions in the SearchView such as clicking on buttons or typing a query.

        IMPL.setOnQueryTextListener(searchView, listener.mListener);
    
public static voidsetQuery(android.view.View searchView, java.lang.CharSequence query, boolean submit)
Sets a query string in the text field and optionally submits the query as well.

param
searchView The SearchView to operate on.
param
query the query string. This replaces any query text already present in the text field.
param
submit whether to submit the query right now or only update the contents of text field.

        IMPL.setQuery(searchView, query, submit);
    
public static voidsetQueryHint(android.view.View searchView, java.lang.CharSequence hint)
Sets the hint text to display in the query text field. This overrides any hint specified in the SearchableInfo.

param
searchView The SearchView to operate on.
param
hint the hint text to display

        IMPL.setQueryHint(searchView, hint);
    
public static voidsetQueryRefinementEnabled(android.view.View searchView, 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 {@link #setSearchableInfo(View, ComponentName)} and not when using a custom adapter.

param
searchView The SearchView to operate on.
param
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
SearchManager#SUGGEST_COLUMN_FLAGS
see
SearchManager#FLAG_QUERY_REFINEMENT

        IMPL.setQueryRefinementEnabled(searchView, enable);
    
public static voidsetSearchableInfo(android.view.View searchView, android.content.ComponentName searchableComponent)
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.

param
searchView The SearchView to operate on.
param
searchableComponent The application component whose {@link android.app.SearchableInfo} should be loaded and applied to the SearchView.

        IMPL.setSearchableInfo(searchView, searchableComponent);
    
public static voidsetSubmitButtonEnabled(android.view.View searchView, 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.

param
searchView The SearchView to operate on.
param
enabled true to show a submit button for submitting queries, false if a submit button is not required.

        IMPL.setSubmitButtonEnabled(searchView, enabled);