arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 668 forks source link

Reversed list of suggestions after recreating view. #252

Open Gloix opened 7 years ago

Gloix commented 7 years ago

When a search is done, the list of results appears in the right order, but after the view hierarchy is destroyed and then later recreated, the results are reversed.

eduardbosch commented 7 years ago

Hi @Gloix,

Could you add some details to your problem?

Maybe your problem is that you are swapping the suggestions with an array and then you try to swap the suggestions again with the same array instance. If FloatingSearchView had to reverse the suggestions list, then, your array has been reversed twice, so the suggestions list appears reversed.

If you want to maintain and reuse a suggestions list, then you should pass a copy to the FloatingSearchView.swapSuggestions:

public class MyClass {
  FloatingSearchView mSearchView;
  ArrayList<SearchSuggestion> mMySuggestions;

...

  private void updateSuggestions() {
    mSearchView.swapSuggestions(new ArrayList<>(mMySuggestions));
  }

...

}

If this is not your problem, you can check at this fix I've just created #262

eduardbosch commented 7 years ago

I've found another problem with reversed suggestions.

There is a new PR with a fix #263

Gloix commented 7 years ago

Thank you so much :D I think #263 will highly likely solve the issue. Will report back when I test a new version.