diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/models/HeaderItem.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/models/HeaderItem.java index 7d0984aa..30e0a77e 100644 --- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/models/HeaderItem.java +++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/models/HeaderItem.java @@ -10,6 +10,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.items.AbstractHeaderItem; +import eu.davidea.flexibleadapter.items.IFilterable; import eu.davidea.flexibleadapter.items.ISectionable; import eu.davidea.samples.flexibleadapter.R; import eu.davidea.viewholders.FlexibleViewHolder; @@ -19,7 +20,7 @@ *

A Section should not contain others Sections!

* Headers are not Sectionable! */ -public class HeaderItem extends AbstractHeaderItem { +public class HeaderItem extends AbstractHeaderItem implements IFilterable { private static final long serialVersionUID = -7408637077727563374L; @@ -89,6 +90,11 @@ public void bindViewHolder(FlexibleAdapter adapter, HeaderViewHolder holder, int holder.mSubtitle.setText(subTitle); } + @Override + public boolean filter(String constraint) { + return getTitle() != null && getTitle().toLowerCase().trim().contains(constraint); + } + static class HeaderViewHolder extends FlexibleViewHolder { public TextView mTitle; diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java index e3915133..77850a24 100644 --- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java +++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java @@ -2410,12 +2410,21 @@ public synchronized void filterItems(@NonNull List unfilteredItems) { if (hasSearchText()) { int newOriginalPosition = -1; for (T item : unfilteredItems) { + //Check header first + T header = (T) getHeaderOf(item); + if (header != null && filterObject(header, getSearchText()) + && !values.contains(getHeaderOf(item))) { + values.add(header); + } if (filterExpandableObject(item, getSearchText())) { RestoreInfo restoreInfo = getPendingRemovedItem(item); if (restoreInfo != null) { //If found point to the new reference while filtering restoreInfo.filterRefItem = ++newOriginalPosition < values.size() ? values.get(newOriginalPosition) : null; } else { + if (hasHeader(item) && !values.contains(getHeaderOf(item))) { + values.add((T) getHeaderOf(item)); + } values.add(item); newOriginalPosition++; if (isExpandable(item)) {