Kelly
Kelly

Reputation: 63

Search Android RecyclerView

I have a RecyclerView that pulls information from Firebase. I am trying to add a search and refine feature whereby the user can search for a person based on their name, or refine the search results by the price they charge. I have researched many methods, but none seem to address the issue completely. I am new to coding, and I would love some tips on how to get these features working!

enter image description here

Upvotes: 0

Views: 53

Answers (1)

Abhishek Saxena
Abhishek Saxena

Reputation: 81

When you pull the data from Firebase store it in a collection say ArrayList originalList.

Make another ArrayList displayList and initiate it with the original list, that is, displayList = originalList;

Pass displayList to your adapter of recyclerview.

Now you can implement the search feature as you see fit in your UI.

Once the user submit the query, update the displayList accordingly hence keeping the originalList unaltered and use method notifyDataSetChanged() to update the UI with the results.

Important is that you pass displayList to the adapter and make all the changed in the same list only.

Upvotes: 1

Related Questions