I found my solution on my problem. But its a little bit slow. If someone can optimize then feel free to post your answer. :)
Instead of equating object
(this.objects = collection
) variable inside my constructor I place it inside performFiltering
. The idea was to refresh the objects
variable every time performFiltering
method fire.
Some people add TextWatcher
in the TextView to refresh their adapter.
Below is my modified perFormFiltering
protected FilterResults performFiltering(CharSequence constraint) {
EmployeeDetails empFunction = new EmployeeDetails(context);
ArrayList<EmployeeDetails> suggestions = new ArrayList<EmployeeDetails>();
FilterResults filterresults = new FilterResults();
if (constraint != null) {
suggestions.clear();
objects = empFunction.GetAllEmployees();
for (EmployeeDetails employee : objects) {
if (employee.getLastName().toLowerCase().startsWith(constraint.toString().toLowerCase())) {
suggestions.add(employee);
}
}
filterresults.values = suggestions;
filterresults.count = suggestions.size();
}
return filterresults;
}
Thanks