title: Dynamic Section Header Of RecyclerView Using Current Date&Time
body: <p>I'll use RecyclerView for a section header</p>
  <p><strong>I want to create section header when i insert each Date &amp; Time data in SQLite Database</strong></p>
  <p>I followed below links for this solution but haven't been successful</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/36246658/recyclerview-dynamic-sections-not-using-any-3rd-lib?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">Recyclerview Dynamic Sections not using any 3rd lib</a></li>
  <li><a href="https://stackoverflow.com/questions/30752980/add-two-sections-in-recyclerview-android?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">Add two sections in recyclerview android</a></li>
  </ul>
  <p>Please refer the below image</p>
  <p><a href="https://i.stack.imgur.com/zVNcW.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/zVNcW.jpg" alt="enter image description here" /></a></p>
  <p>For above image data using below code OR Section is Static :</p>
  <pre><code>List&lt;Company&gt; childList = new ArrayList&lt;&gt;();
          List&lt;CompanySectionHeader&gt; sectionHeaders = new ArrayList&lt;&gt;();
  
          childList = myDb.getAllCompany();
          sectionHeaders.add(new CompanySectionHeader(childList, &quot;WEDNESDAY 4 APRIL&quot;, 1));
  </code></pre>
  <p><strong>Now If suppose i enter today's data then I create 1 Section Header taking today date</strong></p>
  <p>Below image data section header is Static or data also:</p>
  <p><a href="https://i.stack.imgur.com/fiORY.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/fiORY.jpg" alt="enter image description here" /></a></p>
  <p>Above image data are getting using Below code :</p>
  <pre><code>childList.add(new Company(&quot;Ketul Inc.&quot;, &quot;11/11/2017 3:46 PM&quot;));
          childList.add(new Company(&quot;Atmel Corporation&quot;, &quot;09/19/2017 8:46 PM&quot;));
          childList.add(new Company(&quot;ABC Technologies&quot;, &quot;09/12/2017 7:41 PM&quot;));
          childList.add(new Company(&quot;Huron Capital Partners LLC&quot;, &quot;09/12/2017 7:25 PM&quot;));
          sectionHeaders = new ArrayList&lt;&gt;();
          //Create a List of SectionHeader DataModel implements SectionHeader
          sectionHeaders.add(new CompanySectionHeader(childList, &quot;SATURDAY 7 APRIL&quot;, 2));
  </code></pre>
  <p>Below Code is my <strong><code>SectionHeader.Java</code></strong> :</p>
  <pre><code>public class CompanySectionHeader implements Section&lt;Company&gt;, Comparable&lt;CompanySectionHeader&gt; {
  
      List&lt;Company&gt; childList;
      String sectionText;
      int index;
  
      public CompanySectionHeader(List&lt;Company&gt; childList, String sectionText, int index) {
          this.childList = childList;
          this.sectionText = sectionText;
          this.index = index;
      }
  
      @Override
      public List&lt;Company&gt; getChildItems() {
          return childList;
      }
  
      public String getSectionText() {
          return sectionText;
      }
  
      @Override
      public int compareTo(CompanySectionHeader another) {
          if (this.index &gt; another.index) {
              return -1;
          } else {
              return 1;
          }
      }
  }
  </code></pre>
  <p><strong>Below is my SQLite Database Structure</strong>:</p>
  <pre><code>public String getFromatDate(long dateTime) {
          String formatedDate;
          Calendar calendar = Calendar.getInstance();
          calendar.setTimeInMillis(dateTime);
          Date mDate = calendar.getTime();
          SimpleDateFormat sdf;
          sdf = new SimpleDateFormat(&quot;dd/MM/yyyy hh:mm a&quot;, new Locale(&quot;en&quot;));
          formatedDate = sdf.format(mDate);
          return formatedDate;
      }
  
      public long insertCompany(Company company){
  
          //String sql = null;
          SQLiteDatabase db = dbHelper.getWritableDatabase();
  
          ContentValues values = new ContentValues();
  
          values.put(DatabaseHelper.KEY_COMPANY_NAME, company.getName());
          values.put(DatabaseHelper.KEY_CREATED_AT, System.currentTimeMillis());
          values.put(DatabaseHelper.KEY_UPDATED_AT, System.currentTimeMillis());
          values.put(DatabaseHelper.KEY_COMPANY_WEBSITE,company.getWebsite());
          values.put(DatabaseHelper.KEY_COMPANY_EMAIL,company.getEmail());
          values.put(DatabaseHelper.KEY_COMPANY_PHONE_HOME,company.getPhoneHome());
          
          long company_id = db.insert(COMPANY, null, values);
  
          return company_id;
      }
  </code></pre>
  <p><strong>My Question is How to create section header dynamically</strong></p>
  <p>If u need any code or information you can ask me <strong>:)</strong></p>
  <p>Thanks in Advance :</p>