package com.wangbb.naruto.app.adapter; /** * Created by wangbinbin on 15/5/7. */ import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.TextView; import com.wangbb.naruto.R; import java.util.ArrayList; public class HomeAdapter extends RecyclerView.Adapter<DataViewHolder> { private static final int TYPE_HEADER = 0x0002; private static final int TYPE_ITEM = 0x0000; private static final int TYPE_FOOTER = 0x0001; private Context context; private ArrayList<String> list; private boolean canLoadMore = true; public boolean isCanLoadMore() { return canLoadMore; } public void setCanLoadMore(boolean canLoadMore) { this.canLoadMore = canLoadMore; } public HomeAdapter(Context context, ArrayList<String> list) { this.context = context; this.list = list; } @Override public DataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { DataViewHolder holder = null; switch (viewType) { case TYPE_ITEM: holder = new DataViewHolder(LayoutInflater.from(context).inflate(R.layout.item_home, parent, false)); break; case TYPE_FOOTER: holder = new DataViewHolder(LayoutInflater.from(context).inflate(R.layout.load_more_foorerview, parent, false)); break; } return holder; } @Override public void onBindViewHolder(DataViewHolder holder, int position) { if (canLoadMore && position == list.size()) { } else { holder.getView(TextView.class, R.id.num).setText(list.get(position)); } } @Override public void onViewDetachedFromWindow(DataViewHolder holder) { } @Override public int getItemCount() { if (canLoadMore && list.size() != 0) return list.size() + 1; else return list.size(); } @Override public int getItemViewType(int position) { if (canLoadMore && position == list.size()) return TYPE_FOOTER; else return TYPE_ITEM; } }