Created
August 8, 2019 17:55
-
-
Save muth0mi/b42612b671caa06558688c4efe1cb921 to your computer and use it in GitHub Desktop.
Search Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private List<T> showingList = new ArrayList<>(); // showingList is the collection used by the recyclerView adapter | |
| // Method implementing search | |
| public void performSearch(String query) { | |
| /* ToDo: Show loading progress bars */ | |
| if (!query.isEmpty()) { | |
| // For holding search results | |
| List<T> results = new ArrayList<>(); | |
| // Loop showing list looking for matches | |
| for (T t : showingList){ | |
| // Add any results matching criteria to results list | |
| if (t.toString().toLowerCase().contains(query)) { | |
| results.add(t); | |
| } | |
| } | |
| // Check if there are not results found | |
| if (results.isEmpty()){ | |
| /* ToDo: Show 'No results found' prompt */ | |
| /* ToDo: Hide any loading progress bars */ | |
| } | |
| // Set results to the recyclerView adapter and reload | |
| else { | |
| showingList = results; | |
| notifyDataSetChanged(); | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SearchView sv ; // ....
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@OverRide
public boolean onQueryTextSubmit(String query) {
return false;
}
});