I'm unable to access the .filter(charSequence) method in the Android.Widget class.
Code : To call the filter for the RecyclerView.
@OnTextChanged(R.id.microlocation_activity_filter) void onTextChanged(CharSequence strText) {
recyclerViewAdapter.getFilter().filter(strText);
}
Code : The .getFilter() method in RecyclerViewAdapter
/**
* A method to return the filter instance
* @return FilterClass
*/
public ListFilter getFilter() {
return this.filterclass;
}
Code : Filter Implementation under RecyclerViewAdapter
private class ListFilter extends Filter {
/**
* A method that filters the list according to the query entered
* @param strText The text which will be matched against entries in the list
*/
@Override
protected FilterResults performFiltering(CharSequence strText) {
ArrayList<String> lsTemporaryFilterList = new ArrayList<>();
if(strText != null && !TextUtils.isEmpty(strText)) {
Iterator<String> iterator = lsMicrolocationList.iterator();
do {
String strMicrolocation = iterator.next();
if (strMicrolocation.toLowerCase().contains(strText.toString().toLowerCase()))
lsTemporaryFilterList.add(strMicrolocation);
} while (iterator.hasNext());
} else
lsTemporaryFilterList.addAll(lsMicrolocationList);
FilterResults filterResults = new FilterResults();
filterResults.count = lsTemporaryFilterList.size();
filterResults.values = lsTemporaryFilterList;
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
lsFilteredList = (List<String>) results;
notifyDataSetChanged();
}
}
Error : when I pass just one argument
Error:(77, 40) error: method filter in class Filter cannot be applied to given types; required: CharSequence,FilterListener found: CharSequence reason: actual and formal argument lists differ in length
Error : When I pass two arguments as noted in the previous error
Error:(79, 40) error: filter(CharSequence,FilterListener) in Filter is defined in an inaccessible class or interface
I recommend people go through Android Filter Documentation before answering.
Edit : 17th March '16
I was able to solve the problem. For those who might encounter this later & are looking for a solution, the access modifier for the subclass in this illustration was private. Even though an instance of Filter class was returned from a different method, access to it's internal methods was blocked. .filter() executes the performFiltering() method in a worker thread & a whole lot of other stuff. In order for an class to invoke internal methods to the sub class the access modifier has to be kept public or at least package level depending on whether both files lie in the same package or not.
The class access modifier has to be kept public.