PersistentSearchView
Android library designed to simplify the process of implementing search-related functionality.
Getting Started
- Make sure that you've added the
jcenter()
repository to your top-levelbuild.gradle
file.
- Add the library dependency to your module-level
build.gradle
file.
- Enable the jetifier and androidX support in the top-level
gradle.properties
file.
- Update your
compileSdkVersion
in the module-levelbuild.gradle
file to 28+.
- Update your
com.android.support.appcompat.*
dependency to the newandroidx.appcompat.*
alternative.
- Proceed with the implementation of your own search view.
Basic Implementation
Implementation of a PersistentSearchView with basic functionality involves 2 main steps - declaring a widget inside the XML file of your choice and configuring it in one of the Java/Kotlin classes.
Let's implement a PersistentSearchView with basic functionality by following the steps listed above:
-
Declaring a widget inside the XML file.
XML (click to expand)
-
Configuring the widget in one of the Java/Kotlin classes.
Kotlin (click to expand)
Java (click to expand)
Basic Recent Suggestions Implementation
Implementation of a PersistentSearchView with recent suggestions is pretty much the same as Basic Implementation with one exception: the view configuration.
In this implementation you'll need to provide a bit more configuration for the widget in order to show recent suggestions to the user, such as providing implementation for a couple of listeners as well as fetching suggestions from your data provider and setting them to the search view.
For example, here is the configuration of the widget with recent suggestions functionality:
Java (click to expand)
Kotlin (click to expand)
Basic Regular Suggestions Implementation
Implementation of a PersistentSearchView with regular suggestions is identical to the Basic Recent Suggestions Implementation with one exception: suggestions creation method asRecentSearchSuggestions(searchQueries) should be replaced with asRegularSearchSuggestions(searchQueries).
Advanced Use
See the Sample app.
Difference between recent and regular suggestions
The difference between recent and regular suggestions is that a user can remove recent suggestions from the list while regular suggestions cannot be removed (there is no remove button on the regular suggestions).
For example, here are screenshots of recent suggestions compared to regular:
Recent | Regular |
![]() |
![]() |