Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+24 votes

I am trying to implement a feature where multiple filters can be added at a time, and it works to the point of I can filter multiple times but when I get rid of a filter it doesn't add the cards back in. Any ideas on how I can do that?

asked in CSC305 Fall 2023 by (1 point)

5 Answers

+9 votes

I used an arraylist of cards and cleared the list every time a new search was done, resetting it to the visible list to the full collection of cards and then taking from that list what I need according to the new filters. Rather than altering the old list, I just kinda started from scratch.

answered by (1 point)
+9 votes

I used an observable list of filter objects. Whenever a filter is added or removed the event triggers and it calls the method that filters and displays cards.

answered by (1 point)
+8 votes

The way I worked through it was with an observable list, as it is an Array list that is notified when changed are made and keeps it up to date.

answered by (1 point)
+7 votes

You can add Visible flag to Card Class. Then an applyFilter method that sets this flag based on the filter, then a removeFilter method updates the visibility based on the remaining filters. Then getVisibleCards method returns the currently visible cards.

answered by (1 point)
+6 votes

We have a global List that we use in a method that .collects() a list of filtered cards and observes the changes by setting the new value of List. Ours might be a little different because we use checkboxes that return a boolean value, so that makes it a little more straightforward to see if we should be adding the cards back into the list if the checkbox has been unchecked (false)

answered by (1 point)
...