Searchview In Sherlocklistfragment
I have some troubles using SearchView in my SherlockListFragment.There is a custom ArrayAdapter and a listview which contains one image and two TextViews for each item. Everything
Solution 1:
When the SearchView in Sherlock is expanded it sets the TextView component to "", you can see it from the source:
@OverridepublicvoidonActionViewExpanded() {
if (mExpandedInActionView) return;
mExpandedInActionView = true;
mCollapsedImeOptions = mQueryTextView.getImeOptions();
mQueryTextView.setImeOptions(mCollapsedImeOptions | EditorInfo.IME_FLAG_NO_FULLSCREEN);
mQueryTextView.setText("");
setIconified(false);
}
That's why your filter returns the original data. Contrary, comparing to the android.widget.SearchView it does not set the query to "" when the action view is also collapsed. Long story short you need to omit filtering with "" (unless needed), and also check if you are invalidating the ListView when the filtering is performed, since you havent posted the filtering implementation.
Edit: Example of filtering listview
private class MyFilter extends Filter {
@OverrideprotectedvoidpublishResults(CharSequence constraint, FilterResults results) {
if (results!=null && results.count > 0) {
items = (ArrayList<Data>) results.values;
notifyDataSetChanged();
}
}
@Overrideprotected FilterResults performFiltering(CharSequence constraint) {
constraint = constraint.toString().toLowerCase();
items = mOriginalData;
if (constraint.length() == 0 || constraint.equals("")) {
FilterResultsoriginal=newFilterResults();
original.count = items.size();
original.values = items;
return original;
} else {
List<Data> filtered = newArrayList<Data>();
for (Data l : items) {
if ( SOME CONDITION TO FILTER ){ // YOU NEED TO CHANGE THIS
filtered.add(l);
}
}
FilterResultsnewFilterResults=newFilterResults();
newFilterResults.count = filtered.size();
newFilterResults.values = filtered;
return newFilterResults;
}
}
};
In your adapter:
@OverridepublicFiltergetFilter() {
if (mFilter == null) {
mFilter = newMyFilter();
}
return mFilter;
}
Post a Comment for "Searchview In Sherlocklistfragment"