diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java index 83555ca21..f88398e3b 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java @@ -157,20 +157,20 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener, } private void updateSuggestions(boolean scrollToTop) { - mSuggestionList.clear(); + List suggestions = new ArrayList<>(); String text = mEditText.getText().toString(); if (mSuggestionProvider != null) { - List suggestions = mSuggestionProvider.providerSuggestions(text); - if (suggestions != null && !suggestions.isEmpty()) { - mSuggestionList.addAll(suggestions); + List providerSuggestions = mSuggestionProvider.providerSuggestions(text); + if (providerSuggestions != null && !providerSuggestions.isEmpty()) { + suggestions.addAll(providerSuggestions); } } String[] keywords = mSearchDatabase.getSuggestions(text, 128); for (String keyword : keywords) { - mSuggestionList.add(new KeywordSuggestion(keyword)); + suggestions.add(new KeywordSuggestion(keyword)); } EhTagDatabase ehTagDatabase = EhTagDatabase.getInstance(getContext()); @@ -181,12 +181,13 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener, ArrayList> searchHints = ehTagDatabase.suggest(keyword); for (Pair searchHint : searchHints) { - mSuggestionList.add(new TagSuggestion(searchHint.first, searchHint.second)); + suggestions.add(new TagSuggestion(searchHint.first, searchHint.second)); } } } + mSuggestionList = suggestions; mSuggestionAdapter.notifyDataSetChanged(); if (scrollToTop) {