I am having an adapter where i have two lists one list is for InvestorsList where it comes with the list of investors and the other list is called investorListFull which is used to filter results when searching.
Below is how i have declared the lists
List<Investor> investorList;
List<Investor> investorListFull;
Below is how the lists are assigned in my recyclerview adapter constructor
public InvestorsAdapter(Context context, List<Investor> investorList) {
this.context = context;
this.investorList = investorList;
investorListFull = new ArrayList<>(investorList);
}
Below is how i am filtering results in investors list
public Filter getInvestorFilter() {
return investorFilter;
}
private final Filter investorFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<Investor> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(investorListFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
for (Investor investor : investorListFull) {
if (investor.getUsername().toLowerCase().contains(filterPattern)) {
filteredList.add(investor);
}
if (investor.getDateJoined().toLowerCase().contains(filterPattern)) {
filteredList.add(investor);
}
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = filteredList;
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults filterResults) {
investorList.clear();
investorList.addAll((List) filterResults.values);
notifyDataSetChanged();
}
};
I am getting Unchecked assignment error in publish results investorList.addAll((List) filterResults.values);