Reputation: 1
okay so i have a function to do searching and filtering. it all works fine, except for this one line at the end, where it is updating the list, after filtering. but i cant do that since this one specific line is stopping all the items from being displayed in the recycler view this is the code and that line at the end is causing the error:
`private void filterBikes() {`
` String searchedText = searchViewLocation.getQuery().toString().toLowerCase();`
String selectedCategory = spinnerFilterCategory.getSelectedItem().toString();
String selectedSortPrice = spinnerSortPrice.getSelectedItem().toString();
` List<Bike> filteredList = bikeList.stream()`
` .filter(p -> TextUtils.isEmpty(searchedText) || p.getName().toLowerCase().contains(searchedText))`
` .filter(p -> selectedCategory.equals("All bikes") || p.getCategory().equals(selectedCategory))`
` .collect(Collectors.toList());
if (selectedSortPrice.equals("Sort by price: Low - High")) {
filteredList.sort((p1, p2) -> Double.compare(p1.getPriceHour(), p2.getPriceHour()));
} else if (selectedSortPrice.equals("Sort by price: High - Low")) {
filteredList.sort((p1, p2) -> Double.compare(p2.getPriceHour(), p1.getPriceHour()));
}
adapter.updateList(filteredList); // this line
}`
i have created the update method in the adapter too so i dont know what the issue is
` public void updateList(List<Bike> newList) {`
` bikeList = newList;`
` notifyDataSetChanged();} `
i tried to do logging, and it just ends up sauing filteredList is 0. the bike size is being passed on, and so is the item count. but once i try searching or filtering, it doesnt work.
im new to stack overflow so im sorry if the code is messy :(( the issue is in that one line where i mentioned // the line!
Upvotes: 0
Views: 25