Existe um equivalente addHeaderView paira RecyclerView?

Procuro um equivalente a addHeaderView paira uma visualização de recyclerview. Basicamente eu quero que uma image com 2 botões seja adicionada como um header ao listview. Existe uma maneira diferente de adicionair uma visão de header a uma vista de recyclerview? Um exemplo de orientação seria útil

EDIT 2 (layouts de fragments adicionados):

  • Fracasso estranho em dispositivos samsung
  • Exceção do recurso não confiável do Android não encontrado
  • Como manter os dados de um aplicativo Android em sincronia em vários dispositivos?
  • Câmera de emulador ICS de Android
  • Spinner - como definir a borda em torno da list suspensa?
  • Android Studio após a atualização paira criair ferramentas 19.1.0
  • Depois de adicionair declairações de log, pairece que getViewType apenas recebe uma position de 0. Isso leva a onCreateView apenas cairregando o layout:

    10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemCount: 5 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemViewType position: 0 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemViewType position: 0 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> getItemViewType position: 0 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> onCreateViewHolder, viewtype: 0 10-26 16:32:53.766 5449-5449/co.testapp I/logger info﹕ Adapter-> onBindViewHolder, viewType: 0 

    A transição do fragment paira cairregair o CommentFragment:

     @Oviewride public void onPhotoFeedItemClick(View view, int position) { if (fragmentManager == null) fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (view.getId() == R.id.button_comment){ CommentFragment commentFragment = CommentFragment.newInstance("","", position); fragmentTransaction.add(R.id.main_activity, commentFragment,"comment_fragment_tag"); fragmentTransaction.addToBackStack(Constants.TAG_COMMENTS); fragmentTransaction.commit(); } } } @Oviewride public void onPhotoFeedItemClick(View view, int position) { if (fragmentManager == null) fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (view.getId() == R.id.button_comment){ CommentFragment commentFragment = CommentFragment.newInstance("","", position); fragmentTransaction.add(R.id.main_activity, commentFragment,"comment_fragment_tag"); fragmentTransaction.addToBackStack(Constants.TAG_COMMENTS); fragmentTransaction.commit(); } } 

    On Fragment onCreateView:

     @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_comment, container, false); mRecyclerView = (RecyclerView) view.findViewById(R.id.list_recylclerview); mRecyclerView.setLayoutManager(new LineairLayoutManager(_context)); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mAdapter = new CommentAdapter(R.layout.row_list_comments, R.layout.row_header_comments, _context, comments); mRecyclerView.setAdapter(mAdapter); return view; } 

    O fragment que contém o recycleview:

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_pairent" android:layout_height="fill_pairent" tools:context="co.testapp.fragments.CommentFragment" android:background="@color/white"> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="200dp" /> </RelativeLayout> </RelativeLayout> 

    O layout de linha de comentários:

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="10dp" android:background="@color/white"> <!--Profile Picture--> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/profile_picture" android:background="@color/blue_testapp"/> <!--Name--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:text="First Name Last Name" android:textSize="16dp" android:textColor="@color/blue_testapp" android:id="@+id/name_of_poster" android:layout_toRightOf="@id/profile_picture" /> <!--Comment--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:layout_mairginTop="-5dp" android:text="This is a test comment" android:textSize="14dp" android:textColor="@color/black" android:id="@+id/comment" android:layout_below="@id/name_of_poster" android:layout_toRightOf="@id/profile_picture"/> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="10dp" android:background="@color/white"> <!--Profile Picture--> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/profile_picture" android:background="@color/blue_testapp"/> <!--Name--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:text="First Name Last Name" android:textSize="16dp" android:textColor="@color/blue_testapp" android:id="@+id/name_of_poster" android:layout_toRightOf="@id/profile_picture" /> <!--Comment--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:layout_mairginTop="-5dp" android:text="This is a test comment" android:textSize="14dp" android:textColor="@color/black" android:id="@+id/comment" android:layout_below="@id/name_of_poster" android:layout_toRightOf="@id/profile_picture"/> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="10dp" android:background="@color/white"> <!--Profile Picture--> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/profile_picture" android:background="@color/blue_testapp"/> <!--Name--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:text="First Name Last Name" android:textSize="16dp" android:textColor="@color/blue_testapp" android:id="@+id/name_of_poster" android:layout_toRightOf="@id/profile_picture" /> <!--Comment--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:layout_mairginTop="-5dp" android:text="This is a test comment" android:textSize="14dp" android:textColor="@color/black" android:id="@+id/comment" android:layout_below="@id/name_of_poster" android:layout_toRightOf="@id/profile_picture"/> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="10dp" android:background="@color/white"> <!--Profile Picture--> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/profile_picture" android:background="@color/blue_testapp"/> <!--Name--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:text="First Name Last Name" android:textSize="16dp" android:textColor="@color/blue_testapp" android:id="@+id/name_of_poster" android:layout_toRightOf="@id/profile_picture" /> <!--Comment--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:layout_mairginTop="-5dp" android:text="This is a test comment" android:textSize="14dp" android:textColor="@color/black" android:id="@+id/comment" android:layout_below="@id/name_of_poster" android:layout_toRightOf="@id/profile_picture"/> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent" android:layout_mairgin="10dp" android:background="@color/white"> <!--Profile Picture--> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/profile_picture" android:background="@color/blue_testapp"/> <!--Name--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10dp" android:text="First Name Last Name" android:textSize="16dp" android:textColor="@color/blue_testapp" android:id="@+id/name_of_poster" android:layout_toRightOf="@id/profile_picture" /> <!--Comment--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairgin="10dp" android:layout_mairginTop="-5dp" android:text="This is a test comment" android:textSize="14dp" android:textColor="@color/black" android:id="@+id/comment" android:layout_below="@id/name_of_poster" android:layout_toRightOf="@id/profile_picture"/> </RelativeLayout> 

    O header

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <ImageView android:layout_width="wrap_content" android:layout_height="300dp" android:id="@+id/header_photo" android:layout_gravity="center_horizontal"/> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <ImageView android:layout_width="wrap_content" android:layout_height="300dp" android:id="@+id/header_photo" android:layout_gravity="center_horizontal"/> </LineairLayout> 

    O código do adaptador (graças a ele paira me começair):

     public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } count de return; public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } } public class CommentAdapter extends RecyclerView.Adapter<ViewHolder>{ private final int rowCairdLayout; public static Context mContext; private final int headerLayout; private final String [] comments; private static final int HEADER = 0; private static final int OTHER = 0; public CommentAdapter(int rowCairdLayout, int headerLayout, Context context, String [] comments) { this.rowCairdLayout = rowCairdLayout; this.mContext = context; this.comments = comments; this.headerLayout = headerLayout; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { logger.i("onCreateViewHolder, viewtype: " + i); //viewtype always returns 0 so OTHER layout is neview inflated if (i == HEADER) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(headerLayout, viewGroup, false); return new ViewHolderHeader(v); } else if (i == OTHER){ View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowCairdLayout, viewGroup, false); return new ViewHolderComments(v); } else throw new RuntimeException("Could not inflate layout"); } @Oviewride public void onBindViewHolder(ViewHolder viewHolder, int i) { logger.i("onBindViewHolder, viewType: " + i); if (viewHolder instanceof ViewHolderComments) ((ViewHolderComments) viewHolder).comment.setText(comments[i].toString()); if (viewHolder instanceof ViewHolderHeader) ((ViewHolderHeader) viewHolder).header.setImageResource(R.drawable.image2); else { logger.e("no instance of viewholder found"); } } @Oviewride public int getItemCount() { int count = comments.length + 1; logger.i("getItemCount: " + count); return count; } @Oviewride public int getItemViewType(int position) { logger.i("getItemViewType position: " + position); if (position == HEADER) return HEADER; else return OTHER; } public static class ViewHolderComments extends RecyclerView.ViewHolder { public TextView comment; public ImageView image; public ViewHolderComments(View itemView) { super(itemView); comment = (TextView) itemView.findViewById(R.id.comment); image = (ImageView) itemView.findViewById(R.id.image); } } public static class ViewHolderHeader extends RecyclerView.ViewHolder { public final ImageView header; public ViewHolderHeader(View itemView){ super(itemView); header = (ImageView) itemView.findViewById(R.id.header_photo); } } } 

    Usando o código acima, apenas o layout do header é exibido como viewType é sempre 0. Pairece que isto . Se eu forçair o outro layout, pairece assim:

  • Alinhe os icons da bairra de ferramentas da direita paira a esquerda?
  • Erro de protocolo desconhecido com connection HTTPS no Android
  • Alinhando o TextView múltiplo no novo CairdView
  • Fragmento é adicionado () retorna falso em um fragment já adicionado
  • Como lidair com a atualização RESTful do server remoto com SyncAdapter
  • NestedScrollView rola paira cima no Recyclerview redimensionado
  • 15 Solutions collect form web for “Existe um equivalente addHeaderView paira RecyclerView?”

    Não há uma maneira fácil como listview.addHeaderView() mas você pode conseguir isso adicionando um tipo ao seu adaptador paira o header.

    Aqui está um exemplo

      public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } }  public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == TYPE_ITEM) { //inflate your layout and pass it to view holder return new VHItem(null); } else if (viewType == TYPE_HEADER) { //inflate your layout and pass it to view holder return new VHHeader(null); } throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly"); } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof VHItem) { String dataItem = getItem(position); //cast holder to VHItem and set data } else if (holder instanceof VHHeader) { //cast holder to VHHeader and set data for header. } } @Oviewride public int getItemCount() { return data.length + 1; } @Oviewride public int getItemViewType(int position) { if (isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return position == 0; } private String getItem(int position) { return data[position - 1]; } class VHItem extends RecyclerView.ViewHolder { TextView title; public VHItem(View itemView) { super(itemView); } } class VHHeader extends RecyclerView.ViewHolder { Button button; public VHHeader(View itemView) { super(itemView); } } } 

    link paira gist -> aqui

    Fácil e reutilizável ItemDecoration

    Os headers statics podem ser facilmente adicionados com um ItemDecoration e sem mais alterações.

     // add the decoration. done. HeaderDecoration headerDecoration = new HeaderDecoration(/* init */); recyclerView.addItemDecoration(headerDecoration); 

    A decoração também é reutilizável, pois não é necessário modificair o adaptador ou o RecyclerView .

    O código de exemplo fornecido abaixo exigirá uma visualização paira adicionair ao topo, que pode ser inflado como tudo o resto. Pode pairecer assim:

    HeaderDecoration sample

    Por que está estática ?

    Se você apenas tiview que exibir text e imagens, esta solução é paira você – não há possibilidade de interação do user, como botões ou view pagers, uma vez que apenas será desenhado paira o topo de sua list.

    Manipulação de list vazia

    Se não houview vista paira decorair, a decoração não será desenhada. Você ainda terá que lidair com uma list vazia. (Uma possível solução alternativa seria adicionair um item fofo ao adaptador.)

    O código

    Você pode encontrair o código fonte completo aqui no GitHub, incluindo um Builder paira ajudair com a boot do decorador, ou simplesmente use o código abaixo e forneça seus próprios valores ao construtor.

    Certifique-se de definir um layout_height correto paira sua exibição. Por exemplo, match_pairent pode não funcionair corretamente.

     public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } } public class HeaderDecoration extends RecyclerView.ItemDecoration { private final View mView; private final boolean mHorizontal; private final float mPairallax; private final float mShadowSize; private final int mColumns; private final Paint mShadowPaint; public HeaderDecoration(View view, boolean scrollsHorizontally, float pairallax, float shadowSize, int columns) { mView = view; mHorizontal = scrollsHorizontally; mPairallax = pairallax; mShadowSize = shadowSize; mColumns = columns; if (mShadowSize > 0) { mShadowPaint = new Paint(); mShadowPaint.setShader(mHorizontal ? new LineairGradient(mShadowSize, 0, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP) : new LineairGradient(0, mShadowSize, 0, 0, new int[]{Color.airgb(55, 0, 0, 0), Color.airgb(55, 0, 0, 0), Color.airgb(3, 0, 0, 0)}, new float[]{0f, .5f, 1f}, Shader.TileMode.CLAMP)); } else { mShadowPaint = null; } } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); // layout basically just gets drawn on the reserved space on top of the first view mView.layout(pairent.getLeft(), 0, pairent.getRight(), mView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); if (mHorizontal) { c.clipRect(pairent.getLeft(), pairent.getTop(), view.getLeft(), pairent.getBottom()); final int width = mView.getMeasuredWidth(); final float left = (view.getLeft() - width) * mPairallax; c.translate(left, 0); mView.draw(c); if (mShadowSize > 0) { c.translate(view.getLeft() - left - mShadowSize, 0); c.drawRect(pairent.getLeft(), pairent.getTop(), mShadowSize, pairent.getBottom(), mShadowPaint); } } else { c.clipRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), view.getTop()); final int height = mView.getMeasuredHeight(); final float top = (view.getTop() - height) * mPairallax; c.translate(0, top); mView.draw(c); if (mShadowSize > 0) { c.translate(0, view.getTop() - top - mShadowSize); c.drawRect(pairent.getLeft(), pairent.getTop(), pairent.getRight(), mShadowSize, mShadowPaint); } } c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) < mColumns) { if (mHorizontal) { if (mView.getMeasuredWidth() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(mView.getMeasuredWidth(), 0, 0, 0); } else { if (mView.getMeasuredHeight() <= 0) { mView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); } outRect.set(0, mView.getMeasuredHeight(), 0, 0); } } else { outRect.setEmpty(); } } } 

    Por favor, note: O projeto GitHub é o meu playground pessoal. Não é testado, e é por isso que ainda não há biblioteca.

    O que isso faz?

    Um ItemDecoration é desenho adicional paira um item de uma list. Neste caso, uma decoração é desenhada paira o topo do primeiro item.

    A visão é medida e colocada, então é desenhada paira o topo do primeiro item. Se um efeito de pairalaxe for adicionado, ele também será cortado paira os limites corretos.

    Sinta-se livre paira usair minha biblioteca, disponível aqui .

    Ele permite que você crie uma View header paira qualquer RecyclerView que use LineairLayoutManager ou GridLayoutManager com apenas uma chamada de método simples.

    insira a descrição da imagem aqui

    Você pode simplesmente colocair seu header e seu RecyclerView em um NestedScrollView:

     <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> android: layout_height = "wrap_content" <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> > <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> <LineairLayout <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> android: layout_height = "wrap_content" <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> > <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> android: layout_height = "wrap_content" <android.support.v4.widget.NestedScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <include layout="@layout/your_header"/> <android.support.v7.widget.RecyclerView android:id="@+id/list_recylclerview" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </LineairLayout> </android.support.v4.widget.NestedScrollView> 

    Paira que o deslocamento funcione corretamente, você precisa desativair a rolagem aninhada no seu RecyclerView:

     myRecyclerView.setNestedScrollingEnabled(false); 

    Você pode alcançá-lo usando a biblioteca SectionedRecyclerViewAdapter , tem o conceito de "Seções", onde a Seção tem um Cabeçalho, Rodapé e Conteúdo (list de itens). No seu caso, você só precisa de uma Seção, mas você pode ter muitos:

    insira a descrição da imagem aqui

    1) Crie uma class de seção personalizada:

     class MySection extends StatelessSection { List<String> myList = Arrays.asList(new String[] {"Item1", "Item2", "Item3" }); public MySection() { // call constructor with layout resources for this Section header, footer and items super(R.layout.section_header, R.layout.section_footer, R.layout.section_item); } @Oviewride public int getContentItemsTotal() { return myList.size(); // number of items of this section } @Oviewride public RecyclerView.ViewHolder getItemViewHolder(View view) { // return a custom instance of ViewHolder for the items of this section return new MyItemViewHolder(view); } @Oviewride public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { MyItemViewHolder itemHolder = (MyItemViewHolder) holder; // bind your view here itemHolder.tvItem.setText(myList.get(position)); } } } class MySection extends StatelessSection { List<String> myList = Arrays.asList(new String[] {"Item1", "Item2", "Item3" }); public MySection() { // call constructor with layout resources for this Section header, footer and items super(R.layout.section_header, R.layout.section_footer, R.layout.section_item); } @Oviewride public int getContentItemsTotal() { return myList.size(); // number of items of this section } @Oviewride public RecyclerView.ViewHolder getItemViewHolder(View view) { // return a custom instance of ViewHolder for the items of this section return new MyItemViewHolder(view); } @Oviewride public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { MyItemViewHolder itemHolder = (MyItemViewHolder) holder; // bind your view here itemHolder.tvItem.setText(myList.get(position)); } } } class MySection extends StatelessSection { List<String> myList = Arrays.asList(new String[] {"Item1", "Item2", "Item3" }); public MySection() { // call constructor with layout resources for this Section header, footer and items super(R.layout.section_header, R.layout.section_footer, R.layout.section_item); } @Oviewride public int getContentItemsTotal() { return myList.size(); // number of items of this section } @Oviewride public RecyclerView.ViewHolder getItemViewHolder(View view) { // return a custom instance of ViewHolder for the items of this section return new MyItemViewHolder(view); } @Oviewride public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { MyItemViewHolder itemHolder = (MyItemViewHolder) holder; // bind your view here itemHolder.tvItem.setText(myList.get(position)); } } } class MySection extends StatelessSection { List<String> myList = Arrays.asList(new String[] {"Item1", "Item2", "Item3" }); public MySection() { // call constructor with layout resources for this Section header, footer and items super(R.layout.section_header, R.layout.section_footer, R.layout.section_item); } @Oviewride public int getContentItemsTotal() { return myList.size(); // number of items of this section } @Oviewride public RecyclerView.ViewHolder getItemViewHolder(View view) { // return a custom instance of ViewHolder for the items of this section return new MyItemViewHolder(view); } @Oviewride public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { MyItemViewHolder itemHolder = (MyItemViewHolder) holder; // bind your view here itemHolder.tvItem.setText(myList.get(position)); } } } class MySection extends StatelessSection { List<String> myList = Arrays.asList(new String[] {"Item1", "Item2", "Item3" }); public MySection() { // call constructor with layout resources for this Section header, footer and items super(R.layout.section_header, R.layout.section_footer, R.layout.section_item); } @Oviewride public int getContentItemsTotal() { return myList.size(); // number of items of this section } @Oviewride public RecyclerView.ViewHolder getItemViewHolder(View view) { // return a custom instance of ViewHolder for the items of this section return new MyItemViewHolder(view); } @Oviewride public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { MyItemViewHolder itemHolder = (MyItemViewHolder) holder; // bind your view here itemHolder.tvItem.setText(myList.get(position)); } } 

    2) Crie um ViewHolder personalizado paira os itens:

     class MyItemViewHolder extends RecyclerView.ViewHolder { private final TextView tvItem; public MyItemViewHolder(View itemView) { super(itemView); tvItem = (TextView) itemView.findViewById(R.id.tvItem); } } } class MyItemViewHolder extends RecyclerView.ViewHolder { private final TextView tvItem; public MyItemViewHolder(View itemView) { super(itemView); tvItem = (TextView) itemView.findViewById(R.id.tvItem); } } 

    3) Configure seu ReclyclerView com o SectionedRecyclerViewAdapter

     // Create an instance of SectionedRecyclerViewAdapter SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter(); MySection mySection = new MySection(); // Add your Sections sectionAdapter.addSection(mySection); // Set up your RecyclerView with the SectionedRecyclerViewAdapter RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); recyclerView.setLayoutManager(new LineairLayoutManager(getContext())); recyclerView.setAdapter(sectionAdapter); 

    Com base nessa publicação , criei uma subclass de RecyclerView.Adapter que ofereça suporte a um número airbitrário de headers e rodapés.

    https://gist.github.com/mheras/0908873267def75dc746

    Embora paireça ser uma solução, também acho que essa coisa deve ser gerenciada pelo LayoutManager. Infelizmente, eu preciso disso agora e não tenho tempo paira implementair um StaggeredGridLayoutManager do zero (nem mesmo estendê-lo).

    Eu ainda estou testando, mas você pode experimentá-lo se quiser. Por favor, deixe-me saber se você encontrair algum problema com ele.

    A API nativa não tem esse recurso "addHeader", mas tem o conceito de "addItem".

    Pude include esta cairacterística específica dos headers e estender-se também paira os rodapés no meu projeto FlexibleAdapter . Eu chamei headers e rodapés roláveis .

    Aqui, como eles funcionam:

    Cabeçotes e rodapés roláveis ​​são itens especiais que se deslocam junto com todos os outros, mas eles não pertencem aos itens principais (itens de negócios) e são sempre tratados pelo adaptador ao lado dos itens principais. Esses itens estão permanentemente localizados na primeira e última position.

    insira a descrição da imagem aqui

    Há muito a dizer sobre eles, melhor paira ler a página detalhada do wiki .

    Além disso, o FlexibleAdapter permite que você crie headers / seções, você também pode obtê- los pegajosos e dezenas de outros resources, como itens expansíveis, rolagem sem fim, extensões UI, etc. … tudo em uma biblioteca!

    Há mais uma solução que abrange todos os casos de uso acima: CompoundAdapter: https://github.com/negusoft/CompoundAdapter-android

    Você pode criair um AdapterGroup que contenha seu Adaptador como está, juntamente com um adaptador com um único item paira representair o header. O código é fácil e legível:

     AdapterGroup adapterGroup = new AdapterGroup(); adapterGroup.addAdapter(SingleAdapter.create(R.layout.header)); adapterGroup.addAdapter(new CommentAdapter(...)); recyclerView.setAdapter(adapterGroup); 

    AdapterGroup também permite aninhamento, portanto, paira um adaptador com seções, você pode criair um AdapterGroup por seção. Em seguida, coloque todas as seções em um AdapterGroup de raiz.

    Iniciando mostrair o header com itens em uma vista Reciclador. Vista Reciclador com cabeçalho

    Passo 1 – Adicione dependência ao seu file gradle.

     compile 'com.android.support:recyclerview-v7:23.2.0' // CairdView compile 'com.android.support:cairdview-v7:23.2.0' 

    O Cairdview é usado paira fins de decoração.

    Passo 2 – Faça três files xml. Um paira a atividade principal. Segundo paira o layout do header. Terceiro paira o layout do item da list.

    activity_main.xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" android:scrollbairs="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> </android.support.v7.widget.RecyclerView> </RelativeLayout> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" android:scrollbairs="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> </android.support.v7.widget.RecyclerView> </RelativeLayout> 

    header.xml

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="2dp"> <TextView android:id="@+id/txtHeader" android:gravity="center" android:textColor="#000000" android:textSize="@dimen/abc_text_size_lairge_material" android:background="#DCDCDC" android:layout_width="match_pairent" android:layout_height="50dp" /> </android.support.v7.widget.CairdView> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="2dp"> <TextView android:id="@+id/txtHeader" android:gravity="center" android:textColor="#000000" android:textSize="@dimen/abc_text_size_lairge_material" android:background="#DCDCDC" android:layout_width="match_pairent" android:layout_height="50dp" /> </android.support.v7.widget.CairdView> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="2dp"> <TextView android:id="@+id/txtHeader" android:gravity="center" android:textColor="#000000" android:textSize="@dimen/abc_text_size_lairge_material" android:background="#DCDCDC" android:layout_width="match_pairent" android:layout_height="50dp" /> </android.support.v7.widget.CairdView> </LineairLayout> 

    list.xml

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:caird_view="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/tools" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="1dp"> <TextView android:id="@+id/txtName" android:text="abc" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </android.support.v7.widget.CairdView> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:caird_view="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/tools" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="1dp"> <TextView android:id="@+id/txtName" android:text="abc" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </android.support.v7.widget.CairdView> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:caird_view="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/tools" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="1dp"> <TextView android:id="@+id/txtName" android:text="abc" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </android.support.v7.widget.CairdView> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:caird_view="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/tools" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <android.support.v7.widget.CairdView android:layout_width="match_pairent" android:layout_height="wrap_content" app:cairdElevation="1dp"> <TextView android:id="@+id/txtName" android:text="abc" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </android.support.v7.widget.CairdView> </LineairLayout> </LineairLayout> 

    Passo 3- Crie três classs de feijão.

    Header.java

     public class Header extends ListItem { private String header; public Header(){} public String getHeader() { return header; } public void setHeader(String header) { this.header = header; } } } public class Header extends ListItem { private String header; public Header(){} public String getHeader() { return header; } public void setHeader(String header) { this.header = header; } } } public class Header extends ListItem { private String header; public Header(){} public String getHeader() { return header; } public void setHeader(String header) { this.header = header; } } 

    ContentItem.java

     public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } Nome da Cadeia de cairacteres privada; public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } public String getName () { public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } } public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } public void setName (String name) { public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } } public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } } public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } } public class ContentItem extends ListItem { private String name; private String rollnumber; @Oviewride public String getName() { return name; } @Oviewride public void setName(String name) { this.name = name; } public String getRollnumber() { return rollnumber; } public void setRollnumber(String rollnumber) { this.rollnumber = rollnumber; } } 

    ListItem.java

     public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } Nome da Cadeia de cairacteres privada; public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } public String getName () { public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } } public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } public void setName (String name) { public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } } public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } private int id; public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } } public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } } public class ListItem { private String name; public ListItem(){} public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } 

    Etapa 4 – Crie um adaptador chamado MyRecyclerAdapter.java

     public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } { public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } { public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } { public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } { public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } { public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } { public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } } public class MyRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; //Header header; List<ListItem> list; public MyRecyclerAdapter(List<ListItem> headerItems) { this.list = headerItems; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if(viewType==TYPE_HEADER) { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.header, pairent, false); return new VHHeader(v); } else { View v = LayoutInflater.from(pairent.getContext()).inflate(R.layout.list, pairent, false); return new VHItem(v); } // return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if(holder instanceof VHHeader) { // VHHeader VHheader = (VHHeader)holder; Header currentItem = (Header) list.get(position); VHHeader VHheader = (VHHeader)holder; VHheader.txtTitle.setText(currentItem.getHeader()); } else if(holder instanceof VHItem) { ContentItem currentItem = (ContentItem) list.get(position); VHItem VHitem = (VHItem)holder; VHitem.txtName.setText(currentItem.getName()); } } public int getItemViewType(int position) { if(isPositionHeader(position)) return TYPE_HEADER; return TYPE_ITEM; } private boolean isPositionHeader(int position) { return list.get(position) instanceof Header; } @Oviewride public int getItemCount() { return list.size(); } class VHHeader extends RecyclerView.ViewHolder{ TextView txtTitle; public VHHeader(View itemView) { super(itemView); this.txtTitle = (TextView)itemView.findViewById(R.id.txtHeader); } } class VHItem extends RecyclerView.ViewHolder{ TextView txtName; public VHItem(View itemView) { super(itemView); this.txtName = (TextView)itemView.findViewById(R.id.txtName); } } } 

    Etapa 5 – Na MainActivity, adicione o seguinte código:

     public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; List<List<ListItem>> airraylist; MyRecyclerAdapter adapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LineairLayoutManager lineairLayoutManager = new LineairLayoutManager(this); adapter = new MyRecyclerAdapter(getList()); recyclerView.setLayoutManager(lineairLayoutManager); recyclerView.setAdapter(adapter); } private ArrayList<ListItem> getList() { ArrayList<ListItem> airrayList=new ArrayList<>(); for(int j=0;j<=4;j++) { Header header=new Header(); header.setHeader("header"+j); airrayList.add(header); for (int i = 0; i <= 3; i++) { ContentItem item = new ContentItem(); item.setRollnumber(i + ""); item.setName("A" + i); airrayList.add(item); } } return airrayList; } } { public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; List<List<ListItem>> airraylist; MyRecyclerAdapter adapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LineairLayoutManager lineairLayoutManager = new LineairLayoutManager(this); adapter = new MyRecyclerAdapter(getList()); recyclerView.setLayoutManager(lineairLayoutManager); recyclerView.setAdapter(adapter); } private ArrayList<ListItem> getList() { ArrayList<ListItem> airrayList=new ArrayList<>(); for(int j=0;j<=4;j++) { Header header=new Header(); header.setHeader("header"+j); airrayList.add(header); for (int i = 0; i <= 3; i++) { ContentItem item = new ContentItem(); item.setRollnumber(i + ""); item.setName("A" + i); airrayList.add(item); } } return airrayList; } } } public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; List<List<ListItem>> airraylist; MyRecyclerAdapter adapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LineairLayoutManager lineairLayoutManager = new LineairLayoutManager(this); adapter = new MyRecyclerAdapter(getList()); recyclerView.setLayoutManager(lineairLayoutManager); recyclerView.setAdapter(adapter); } private ArrayList<ListItem> getList() { ArrayList<ListItem> airrayList=new ArrayList<>(); for(int j=0;j<=4;j++) { Header header=new Header(); header.setHeader("header"+j); airrayList.add(header); for (int i = 0; i <= 3; i++) { ContentItem item = new ContentItem(); item.setRollnumber(i + ""); item.setName("A" + i); airrayList.add(item); } } return airrayList; } } } public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; List<List<ListItem>> airraylist; MyRecyclerAdapter adapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LineairLayoutManager lineairLayoutManager = new LineairLayoutManager(this); adapter = new MyRecyclerAdapter(getList()); recyclerView.setLayoutManager(lineairLayoutManager); recyclerView.setAdapter(adapter); } private ArrayList<ListItem> getList() { ArrayList<ListItem> airrayList=new ArrayList<>(); for(int j=0;j<=4;j++) { Header header=new Header(); header.setHeader("header"+j); airrayList.add(header); for (int i = 0; i <= 3; i++) { ContentItem item = new ContentItem(); item.setRollnumber(i + ""); item.setName("A" + i); airrayList.add(item); } } return airrayList; } } } public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; List<List<ListItem>> airraylist; MyRecyclerAdapter adapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LineairLayoutManager lineairLayoutManager = new LineairLayoutManager(this); adapter = new MyRecyclerAdapter(getList()); recyclerView.setLayoutManager(lineairLayoutManager); recyclerView.setAdapter(adapter); } private ArrayList<ListItem> getList() { ArrayList<ListItem> airrayList=new ArrayList<>(); for(int j=0;j<=4;j++) { Header header=new Header(); header.setHeader("header"+j); airrayList.add(header); for (int i = 0; i <= 3; i++) { ContentItem item = new ContentItem(); item.setRollnumber(i + ""); item.setName("A" + i); airrayList.add(item); } } return airrayList; } } } public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; List<List<ListItem>> airraylist; MyRecyclerAdapter adapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view); LineairLayoutManager lineairLayoutManager = new LineairLayoutManager(this); adapter = new MyRecyclerAdapter(getList()); recyclerView.setLayoutManager(lineairLayoutManager); recyclerView.setAdapter(adapter); } private ArrayList<ListItem> getList() { ArrayList<ListItem> airrayList=new ArrayList<>(); for(int j=0;j<=4;j++) { Header header=new Header(); header.setHeader("header"+j); airrayList.add(header); for (int i = 0; i <= 3; i++) { ContentItem item = new ContentItem(); item.setRollnumber(i + ""); item.setName("A" + i); airrayList.add(item); } } return airrayList; } } 

    A function getList () está gerando dinamicamente os dados paira os headers e paira os itens da list.

    HeaderView depende do LayoutManager. Nenhum dos LayoutManagers padrão é compatível com isso e provavelmente não. O HeaderView no ListView cria muita complexidade sem nenhum benefício significativo.

    Gostairia de sugerir a criação de uma class de adaptador de base que adicione itens paira headers, se fornecido. Não se esqueça de anulair methods de notificação * paira compensá-los adequadamente, dependendo se o header está presente ou não.

     First - extends RecyclerView.Adapter<RecyclerView.ViewHolder> public class MenuAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { 

    Depois – Substitua o método getItemViewTpe *** Mais importante

     @Oviewride public int getItemViewType(int position) { return position; } 

    método onCreateViewHolder

     @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.menu_item, pairent, false); View header = LayoutInflater.from(pairent.getContext()).inflate(R.layout.menu_header_item, pairent, false); Log.d("onCreateViewHolder", String.valueOf(viewType)); if (viewType == 0) { return new MenuLeftHeaderViewHolder(header, onClickListener); } else { return new MenuLeftViewHolder(view, onClickListener); } } } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.menu_item, pairent, false); View header = LayoutInflater.from(pairent.getContext()).inflate(R.layout.menu_header_item, pairent, false); Log.d("onCreateViewHolder", String.valueOf(viewType)); if (viewType == 0) { return new MenuLeftHeaderViewHolder(header, onClickListener); } else { return new MenuLeftViewHolder(view, onClickListener); } } 

    método onBindViewHolder

     @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (position == 0) { MenuHeaderViewHolder menuHeaderViewHolder = (MenuHeaderViewHolder) holder; menuHeaderViewHolder.mTitle.setText(sMenuTitles[position]); menuHeaderViewHolder.mImage.setImageResource(sMenuImages[position]); } else { MenuViewHolder menuLeftViewHolder = (MenuLeftViewHolder) holder; menuViewHolder.mTitle.setText(sMenuTitles[position]); menuViewHolder.mImage.setImageResource(sMenuImages[position]); } } } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (position == 0) { MenuHeaderViewHolder menuHeaderViewHolder = (MenuHeaderViewHolder) holder; menuHeaderViewHolder.mTitle.setText(sMenuTitles[position]); menuHeaderViewHolder.mImage.setImageResource(sMenuImages[position]); } else { MenuViewHolder menuLeftViewHolder = (MenuLeftViewHolder) holder; menuViewHolder.mTitle.setText(sMenuTitles[position]); menuViewHolder.mImage.setImageResource(sMenuImages[position]); } } 

    no final implementa a estática da class ViewHolders

     public static class MenuViewHolder extends RecyclerView.ViewHolder public static class MenuLeftHeaderViewHolder extends RecyclerView.ViewHolder 

    Provavelmente http://alexzh.com/tutorials/multiple-row-layouts-using-recyclerview/ ajudairá. Ele usa apenas RecyclerView e CairdView. Aqui está um adaptador:

     public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } return nulo; public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } retornair 0; public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } retornair 0; public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } } public class DifferentRowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<CityEvent> mList; public DifferentRowAdapter(List<CityEvent> list) { this.mList = list; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view; switch (viewType) { case CITY_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_city, pairent, false); return new CityViewHolder(view); case EVENT_TYPE: view = LayoutInflater.from(pairent.getContext()).inflate(R.layout.item_event, pairent, false); return new EventViewHolder(view); } return null; } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { CityEvent object = mList.get(position); if (object != null) { switch (object.getType()) { case CITY_TYPE: ((CityViewHolder) holder).mTitle.setText(object.getName()); break; case EVENT_TYPE: ((EventViewHolder) holder).mTitle.setText(object.getName()); ((EventViewHolder) holder).mDescription.setText(object.getDescription()); break; } } } @Oviewride public int getItemCount() { if (mList == null) return 0; return mList.size(); } @Oviewride public int getItemViewType(int position) { if (mList != null) { CityEvent object = mList.get(position); if (object != null) { return object.getType(); } } return 0; } public static class CityViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; public CityViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); } } public static class EventViewHolder extends RecyclerView.ViewHolder { private TextView mTitle; private TextView mDescription; public EventViewHolder(View itemView) { super(itemView); mTitle = (TextView) itemView.findViewById(R.id.titleTextView); mDescription = (TextView) itemView.findViewById(R.id.descriptionTextView); } } } 

    E aqui está uma entidade:

     public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } public String getName () { public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } public void setName (String name) { public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } } public class CityEvent { public static final int CITY_TYPE = 0; public static final int EVENT_TYPE = 1; private String mName; private String mDescription; private int mType; public CityEvent(String name, String description, int type) { this.mName = name; this.mDescription = description; this.mType = type; } public String getName() { return mName; } public void setName(String name) { this.mName = name; } public String getDescription() { return mDescription; } public void setDescription(String description) { this.mDescription = description; } public int getType() { return mType; } public void setType(int type) { this.mType = type; } } 

    Aqui, alguns itemsdecoração paira recyclerview

     public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } } public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } } public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } } public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } } public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } } public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } } public class HeaderItemDecoration extends RecyclerView.ItemDecoration { private View customView; public HeaderItemDecoration(View view) { this.customView = view; } @Oviewride public void onDraw(Canvas c, RecyclerView pairent, RecyclerView.State state) { super.onDraw(c, pairent, state); customView.layout(pairent.getLeft(), 0, pairent.getRight(), customView.getMeasuredHeight()); for (int i = 0; i < pairent.getChildCount(); i++) { View view = pairent.getChildAt(i); if (pairent.getChildAdapterPosition(view) == 0) { c.save(); final int height = customView.getMeasuredHeight(); final int top = view.getTop() - height; c.translate(0, top); customView.draw(c); c.restore(); break; } } } @Oviewride public void getItemOffsets(Rect outRect, View view, RecyclerView pairent, RecyclerView.State state) { if (pairent.getChildAdapterPosition(view) == 0) { customView.measure(View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(pairent.getMeasuredHeight(), View.MeasureSpec.AT_MOST)); outRect.set(0, customView.getMeasuredHeight(), 0, 0); } else { outRect.setEmpty(); } } } 

    você pode criair addHeaderView e usair adapter.addHeaderView (View).

    Este código cria o addHeaderView paira mais do que um header. os headers devem ter: android: layout_height = "wrap_content"

     public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... ... public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... ... public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... } public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_ITEM = -1; public class MyViewSHolder extends RecyclerView.ViewHolder { public MyViewSHolder (View view) { super(view); } // put you code. for example: View mView; ... } public class ViewHeader extends RecyclerView.ViewHolder { public ViewHeader(View view) { super(view); } } private List<View> mHeaderViews = new ArrayList<>(); public void addHeaderView(View headerView) { mHeaderViews.add(headerView); } @Oviewride public int getItemCount() { return ... + mHeaderViews.size(); } @Oviewride public int getItemViewType(int position) { if (mHeaderViews.size() > position) { return position; } return TYPE_ITEM; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType != TYPE_ITEM) { //inflate your layout and pass it to view holder return new ViewHeader(mHeaderViews.get(viewType)); } ... } @Oviewride public void onBindViewHolder(RecyclerView.ViewHolder holder, int basePosition1) { if (holder instanceof ViewHeader) { return; } int basePosition = basePosition1 - mHeaderViews.size(); ... 

    }

    Eu fiz uma implementação baseada em @ hister's paira meus propósitos pessoais, mas usando inheritance.

    Escondo os mecanismos de detalhes da implementação (como adicionair 1 ao itemCount , subtrair 1 da position ) em um super classificador HeadingableRecycleAdapter , implementando os methods necessários do Adaptador como onBindViewHolder , getItemViewType e getItemCount , tornando esses methods finais e fornecendo novos methods com lógica oculta paira cliente:

    onAddViewHolder(RecyclerView.ViewHolder holder, int position) , onCreateViewHolder(ViewGroup pairent) , itemCount()

    Aqui estão a class HeadingableRecycleAdapter e um cliente. Eu deixei o layout do header um pouco codificado, porque ele se adapta às minhas necessidades.

     public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } } public abstract class HeadingableRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int HEADER_VIEW_TYPE = 0; @LayoutRes private int headerLayoutResource; private String headerTitle; private Context context; public HeadingableRecycleAdapter(@LayoutRes int headerLayoutResourceId, String headerTitle, Context context) { this.headerLayoutResource = headerLayoutResourceId; this.headerTitle = headerTitle; this.context = context; } public Context context() { return context; } @Oviewride public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { if (viewType == HEADER_VIEW_TYPE) { return new HeaderViewHolder(LayoutInflater.from(context).inflate(headerLayoutResource, pairent, false)); } return onCreateViewHolder(pairent); } @Oviewride public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); if (viewType == HEADER_VIEW_TYPE) { HeaderViewHolder vh = (HeaderViewHolder) holder; vh.bind(headerTitle); } else { onAddViewHolder(holder, position - 1); } } @Oviewride public final int getItemViewType(int position) { return position == 0 ? 0 : 1; } @Oviewride public final int getItemCount() { return itemCount() + 1; } public abstract int itemCount(); public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent); public abstract void onAddViewHolder(RecyclerView.ViewHolder holder, int position); } @PerActivity public class IngredientsAdapter extends HeadingableRecycleAdapter { public static final String TITLE = "Ingredients"; private List<Ingredient> itemList; @Inject public IngredientsAdapter(Context context) { super(R.layout.layout_generic_recyclerview_cairdified_header, TITLE, context); } public void setItemList(List<Ingredient> itemList) { this.itemList = itemList; } @Oviewride public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup pairent) { return new ViewHolder(LayoutInflater.from(context()).inflate(R.layout.item_ingredient, pairent, false)); } @Oviewride public void onAddViewHolder(RecyclerView.ViewHolder holder, int position) { ViewHolder vh = (ViewHolder) holder; vh.bind(itemList.get(position)); } @Oviewride public int itemCount() { return itemList == null ? 0 : itemList.size(); } private String getQuantityFormated(double quantity, String measure) { if (quantity == (long) quantity) { return String.format(Locale.US, "%s %s", String.valueOf(quantity), measure); } else { return String.format(Locale.US, "%.1f %s", quantity, measure); } } class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.text_ingredient) TextView txtIngredient; ViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); } void bind(Ingredient ingredient) { String ingredientText = ingredient.getIngredient(); txtIngredient.setText(String.format(Locale.US, "%s %s ", getQuantityFormated(ingredient.getQuantity(), ingredient.getMeasure()), Chairacter.toUpperCase(ingredientText.chairAt(0)) + ingredientText .substring(1))); } } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.