I have a RecyclerView
which will show a list of items. I want to provide a filter for my list so that if user select A
, the adapter will skip other types and only show A
.
public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemViewHolder> {
private List<Item> mItems;
private String mSelectedType;
@Override
public void onBindViewHolder(ItemViewHolder holder, int position) {
Item item = mItems.get(position);
if (mSelectedType.equals(item.getType())) {
//bind it
} else {
//skip it
}
}
public void setSelectedType(String selectedType) {
mSelectedType = selectedType;
}
}