package com.ximsfei.skindemo.ui.adapter.baseadapter; import android.support.v7.widget.RecyclerView; import java.util.ArrayList; import java.util.List; /** * Created by ximsfei on 2017/1/15. */ public abstract class BaseRecyclerViewAdapter<T> extends RecyclerView.Adapter<BaseRecyclerViewHolder> { protected List<T> data = new ArrayList<>(); protected OnItemClickListener<T> listener; @Override public void onBindViewHolder(BaseRecyclerViewHolder holder, final int position) { holder.onBaseBindViewHolder(data.get(position), position); } @Override public int getItemCount() { return data.size(); } public void addAll(List<T> data) { this.data.addAll(data); } public void add(T object) { data.add(object); } public void clear() { data.clear(); } public void remove(T object) { data.remove(object); } public void remove(int position) { data.remove(position); } public void removeAll(List<T> data) { this.data.retainAll(data); } public void setOnItemClickListener(OnItemClickListener<T> listener) { this.listener = listener; } public List<T> getData() { return data; } }