Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:21:37+00:00 2026-06-10T23:21:37+00:00

I’m building a custom calendar view for my android app that allows you to

  • 0

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 month view, and everything is working perfectly on the 1-month scale.

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.

I’ve tried adapting this horizontal pager 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…

  1. [July, August, September] (focus is on August, then user swipes to September)
  2. [July, August, September] (focus is now on September)
  3. [August, August, September] (shift August left by one, overwriting July)
  4. [August, September, September] (shift September left by one, overwriting August)
  5. [August, September, September] (set the view to the middle September, so we’re centered again)
  6. [August, September, October] (overwrite the 2nd September with the actual next month)

When I do this, though, there’s a noticeable flash on the screen when swiping to the next month.

Here’s the code for forward scrolling (note: backward scrolling has the same issue)

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));
}

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…

  1. [July, August, September] (focus is on August, then user swipes to September)
  2. [July, August, September] (focus is now on September)
  3. [August, September] (remove July, but store it for recycling)
  4. [August, September, October] (recycle July to instead display October, and add the view)

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.

So what am I doing wrong? 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?

(As a side question, is there any way I can customize the Android CalendarView visually? That would really solve all my problems…)

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:21:38+00:00Added an answer on June 10, 2026 at 11:21 pm

    I ended up getting it to work by extending FragmentStatePagerAdapter, and also integrating user113215’s suggestion. I didn’t go for truly infinite scrolling, but rather virtually infinite (i.e. 10,000 months, or 833 years). Here’s the bulk of my code:

    public static class CalendarAdapter extends FragmentStatePagerAdapter {
        private static final int NUM_MONTHS = 10000;
        private static final int INDEX_EPOCH = NUM_MONTHS/2;
        private static final int MONTHS_PER_YEAR = 12;
        private static final Calendar calendarMonthEpoch = new GregorianCalendar(2012, Calendar.AUGUST, 1);
    
        // ...
    
        @Override
        public int getCount() {
            return NUM_MONTHS;
        }
    
        @Override
        public Fragment getItem(int position) {
            return CalendarMonthFragment.newInstance(calendarMonthAtPosition(position));
        }
    
        private static Calendar calendarMonthAtPosition(int position) {
            int offset = position - INDEX_EPOCH;
            Calendar calMonthAtPosition = (Calendar) calendarMonthEpoch.clone(); 
            calMonthAtPosition.add(Calendar.MONTH, offset % MONTHS_PER_YEAR);
            calMonthAtPosition.add(Calendar.YEAR, offset / MONTHS_PER_YEAR);
    
            return calMonthAtPosition;
        }
    
        // ...
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.