title: Creating sections within a RecyclerView
body: <p>I have worked with listviews for some time now and as I began to understand them, they come out with recyclerview.  I have a simple working example containing all of the items.  I would like to create sections within the recyclerview using the same layout.  For example, each section is filtered by data (Breakfast, lunch, dinner).  How would I create sections within the recyclerview?  If you need more information, or believe it is a bad question, I will update my question or supply more code.  </p>
  
  <p>How I would filter the adapters by breakfast, lunch and dinner:</p>
  
  <pre><code>FoodAdapter mAdapterBreakfast = new FoodAdapter(LogSet.filterBy("Breakfast"), R.layout.row, this);
  FoodAdapter mAdapterLunch = new FoodAdapter(LogSet.filterBy("Lunch"), R.layout.row, this);
  FoodAdapter mAdapterDinner = new FoodAdapter(LogSet.filterBy("Dinner"), R.layout.row, this);
  </code></pre>
  
  <p>How I get all of the items in the adapter:</p>
  
  <pre><code>FoodAdapter mAdapter = new FoodAdapter(LogSet.all(), R.layout.row, this);
  </code></pre>
  
  <p>Here is a working example of all:</p>
  
  <p><strong>Adapter</strong></p>
  
  <pre><code>public class FoodAdapter extends RecyclerView.Adapter&lt;FoodAdapter.ViewHolder&gt; {
      private List&lt;LogSet&gt; meals;
      private int rowLayout;
      private Context mContext;
      View v;
  
      public FoodAdapter(List&lt;LogSet&gt; mMeals, int rowLayout, Context context) {
          this.meals = mMeals;
          this.rowLayout = rowLayout;
          this.mContext = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
          return new ViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(ViewHolder viewHolder, int i) {
          LogSet meal = meals.get(i);
          viewHolder.countryName.setText(meal.getLiftName());
      }
  
      @Override
      public int getItemCount() {
          return meals == null ? 0 : meals.size();
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
          public TextView countryName;
  
          public ViewHolder(View itemView) {
              super(itemView);
              countryName = (TextView) itemView.findViewById(R.id.foodName);
          }
      }
  }
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
      RecyclerView mRecyclerView;
      Date mDate = new Date();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_testing_rec);
          mRecyclerView = (RecyclerView) findViewById(R.id.list);
          mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
          mRecyclerView.setItemAnimator(new DefaultItemAnimator());
          FoodAdapter mAdapter = new FoodAdapter(LogSet.all(), R.layout.row, this);
          mRecyclerView.setAdapter(mAdapter);
          /*
          FoodAdapter mAdapterBreakfast = new FoodAdapter(LogSet.filterBy("Breakfast"), R.layout.row, this);
          FoodAdapter mAdapterLunch = new FoodAdapter(LogSet.filterBy("Lunch"), R.layout.row, this);
          FoodAdapter mAdapterDinner = new FoodAdapter(LogSet.filterBy("Dinner"), R.layout.row, this);
          */
      }
  }
  </code></pre>
  
  <p>Here is how I would send each List value to the adapter:</p>
  
  <p><strong>Adapter</strong></p>
  
  <pre><code>public class FoodAdapter extends RecyclerView.Adapter&lt;FoodAdapter.ViewHolder&gt; {
      private List&lt;LogSet&gt; meals;
      private List&lt;LogSet&gt; breakfast;
      private List&lt;LogSet&gt; lunch;
      private List&lt;LogSet&gt; dinner;
      private int rowLayout;
      private Context mContext;
      View v;
  
      public FoodAdapter(List&lt;LogSet&gt; mMeals, List&lt;LogSet&gt; mBreakfast, List&lt;LogSet&gt; mLunch, List&lt;LogSet&gt; mDinner, int rowLayout, Context context) {
          this.meals = mMeals;
          this.breakfast = mBreakfast;
          this.lunch = mLunch;
          this.dinner = mDinner;
          this.rowLayout = rowLayout;
          this.mContext = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
          return new ViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(ViewHolder viewHolder, int i) {
          LogSet meal = meals.get(i);
          viewHolder.countryName.setText(meal.getLiftName());
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
          public TextView countryName;
  
          public ViewHolder(View itemView) {
              super(itemView);
              countryName = (TextView) itemView.findViewById(R.id.foodName);
          }
      }
  
      @Override
      public int getItemCount() {
          return meals == null ? 0 : meals.size();
      }
  }
  </code></pre>
  
  <p><strong>MainActivity</strong> minus the all()</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
      RecyclerView mRecyclerView;
      Date mDate = new Date();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_testing_rec);
          mRecyclerView = (RecyclerView) findViewById(R.id.list);
          mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
          mRecyclerView.setItemAnimator(new DefaultItemAnimator());
          FoodAdapter mAdapter = new FoodAdapter(LogSet.all(), LogSet.filterBy("Breakfast"), LogSet.filterBy("Lunch"), LogSet.filterBy("Dinner"), R.layout.row, this);
          mRecyclerView.setAdapter(mAdapter);
          /*
          FoodAdapter mAdapterBreakfast = new FoodAdapter(LogSet.filterBy("Breakfast"), R.layout.row, this);
          FoodAdapter mAdapterLunch = new FoodAdapter(LogSet.filterBy("Lunch"), R.layout.row, this);
          FoodAdapter mAdapterDinner = new FoodAdapter(LogSet.filterBy("Dinner"), R.layout.row, this);
          */
      }
  }
  </code></pre>
  
  <p>Again, How would I create sections within the RecyclerView with the Breakfast, Lunch and Dinner? </p>