package com.marshalchen.common.demoofui.recyclerviewstickyheaders.adapters; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.marshalchen.common.demoofui.R; import com.marshalchen.common.uimodule.recyclerviewstickyheaders.StickyHeadersAdapter; import java.util.List; /** * Created by aurel on 24/09/14. */ public class BigramHeaderAdapter implements StickyHeadersAdapter<BigramHeaderAdapter.ViewHolder> { private List<String> items; public BigramHeaderAdapter(List<String> items) { this.items = items; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent) { View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_sticky_head_top_header, parent, false); return new ViewHolder(itemView); } @Override public void onBindViewHolder(ViewHolder headerViewHolder, int position) { headerViewHolder.title.setText(items.get(position).subSequence(0, 2)); } @Override public long getHeaderId(int position) { return items.get(position).subSequence(0, 2).hashCode(); } public static class ViewHolder extends RecyclerView.ViewHolder { TextView title; public ViewHolder(View itemView) { super(itemView); title = (TextView) itemView.findViewById(R.id.title); } } }