I am trying to make a list view search for Android. I have found many tutorials that do just that where a search-bar is placed at the top and if you type in the box the results
Rather than products[position]
, use adapter.getItem(position)
. When the ListView
is not in filter mode, those two things will be the same. But, in filter mode, getItem()
will take the filtering into account.
The ListAdapter will change the relative position of the items it currently shows due to the filtering. You should always use getItem(position)
to retrieve the correct item.