title: Custom calendar view in Android
body: <p>I'm building a custom calendar view for my android app that allows you to swipe between months. I've created custom calendar square views, which I've embedded into a custom calendar <em>month</em> view, and everything is working perfectly on the 1-month scale.</p>
  
  <p>Unfortunately, now I'm stuck. I now want to embed my custom calendar month views into an infinite view pager, so that I can scroll forward and backward through the calendar indefinitely.</p>
  
  <p>I've tried adapting <a href="https://github.com/ysamlan/horizontalpager" rel="noreferrer">this horizontal pager</a> for infinite scrolling by using a simple trick. I hold an array of 3 of my calendar month views and update the list based on where the user scrolls to. Example...</p>
  
  <ol>
  <li>[July, <strong>August</strong>, September] (focus is on August, then user swipes to September)</li>
  <li>[July, August, <strong>September</strong>] (focus is now on September)</li>
  <li>[<em>August</em>, August, <strong>September</strong>] (shift August left by one, overwriting July)</li>
  <li>[August, <em>September</em>, <strong>September</strong>] (shift September left by one, overwriting August)</li>
  <li>[August, <strong>September</strong>, September] (set the view to the middle September, so we're centered again)</li>
  <li>[August, <strong>September</strong>, <em>October</em>] (overwrite the 2nd September with the actual next month)</li>
  </ol>
  
  <p>When I do this, though, there's a noticeable flash on the screen when swiping to the next month.</p>
  
  <p>Here's the code for forward scrolling (note: backward scrolling has the same issue)</p>
  
  <pre><code>private void updateViewsForForwardScroll() {
      // Note: INDEX_PREV = 0; INDEX_CURR = 1; INDEX_NEXT = 2
      ((CalendarMonthView) getChildAt(INDEX_PREV)).showMonth(oneMonthPriorTo(currentMonth));
      ((CalendarMonthView) getChildAt(INDEX_CURR)).showMonth(currentMonth);
      setCurrentScreen(INDEX_CURR, false);
      ((CalendarMonthView) getChildAt(INDEX_NEXT)).showMonth(oneMonthAfter(currentMonth));
  }
  </code></pre>
  
  <p>I think the problem is that setCurrentScreen() finishes before showMonth(currentMonth), so the view at INDEX_CURR is still updating when the screen is set. I tried solving that by using the following strategy instead...</p>
  
  <ol>
  <li>[July, <strong>August</strong>, September] (focus is on August, then user swipes to September)</li>
  <li>[July, August, <strong>September</strong>] (focus is now on September)</li>
  <li>[August, <strong>September</strong>] (remove July, but store it for recycling)</li>
  <li>[August, <strong>September</strong>, October] (recycle July to instead display October, and add the view)</li>
  </ol>
  
  <p>I haven't touched the currently focused view at all, but there's still a flash! This time, the screen flashes from September, to August, then back to September. </p>
  
  <p>So <strong>what am I doing wrong?</strong> Is there a way to do what I'm trying to do without the user knowing about it? If not, is there an existing class I can leverage?</p>
  
  <p>(As a side question, is there any way I can customize the Android CalendarView visually? That would really solve all my problems...)</p>
  
  <p>Thanks in advance!</p>