3

I'm using the MaterialSearchView library. When I search for the first time, the correct elements are returned. If I click on the first result, the correct element is selected and the itemName is printed out in the logcat. If I search again for another item, the correct elements are again returned but if I select any of the results, the old item is printed (from the previous search) and not the one I have selected.

This is my code:

materialSearchView.setOnItemClickListener((adapterView, view, position, l) -> {
    String itemName = itemNames.get(position);
    materialSearchView.closeSearch();
    Log.d(TAG, itemName);
});

Any ideas? Thanks!

Johans Bormman
  • 855
  • 2
  • 11
  • 23
  • Where is `itemNames` actually defined? Also, consider opening an issue on their GitHub repository for this problem. You are more likely to get a faster response there. – Yashovardhan99 Apr 04 '19 at 17:28
  • Can you share the code where you are declaring it. Seems like the problem is with that rather than the clickListener as you are only getting a position attribute here rather than the list of items. – Yashovardhan99 Apr 04 '19 at 17:39
  • Ya, that's was it, an issue regarding the position. The position was correct but the list was filled up with old elements. Thanks anyway for that! – Johans Bormman Apr 04 '19 at 17:50
  • No problem! I have added an answer just in case someone faces the same issue in the future. If you add more details on the list, I will update the answer with more details on how the issue was fixed. – Yashovardhan99 Apr 04 '19 at 18:10

1 Answers1

0

The problem lies with itemNames and not the OnItemClickListener. The listener is only returning the position on the list of items (which seems to be correct) but the list may have not been updated.

Check the contents of the list itemNames and update it accordingly when a new search is made. I can't comment on how it's to be done without looking at the rest of the code.

Yashovardhan99
  • 887
  • 11
  • 26