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 3663164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:29:57+00:00 2026-05-19T01:29:57+00:00

i have created a calendar where a suer can scroll through previous and next

  • 0

i have created a calendar where a suer can scroll through previous and next months calendar but the issue i am having is when the user tries to scroll into the previous month.

when the user clicks to the previous month the first time the app is run, it works but when the user clicks again it doesnt dispite the value i am sending to the Calendar.Set() being 100% correct and even debugged it yet the actual calendar doesnt update and therefore returns me the same month as the current one!

here is my code below.

@Override
public void onClick(View v) {

    // get current month

    int currentMonth = mCurrentMonth.get(Calendar.MONTH);
    Log.d(TAG, "day = " + mCurrentMonth.get(Calendar.DAY_OF_MONTH));

    Log.d(TAG, "currentMonth in onClick = " + currentMonth);
    if (v == mPreviousMonthButton) {
        Log.d(TAG, "mPreviousMonthButton CLICKED ");

        // if current month is january
        // decrement the current year and set month to december

        if (currentMonth == Calendar.JANUARY) {
            int currentYear = mCurrentMonth.get(Calendar.YEAR);
            mCurrentMonth.set(Calendar.YEAR, currentYear - 1);
            mCurrentMonth.set(Calendar.MONTH, Calendar.DECEMBER);
        } else {

            // else decrement the month

            Log.d(TAG, "currentMonth-- = " + currentMonth);
            mCurrentMonth.set(Calendar.MONTH, currentMonth);
            Log.d(TAG,
                    "month in previus button = "
                            + mCurrentMonth.get(Calendar.MONTH));

        }
        // save the month

        setDateForMonth();

    } else if (v == mNextMonthButton) {
        Log.d(TAG, "mNextMonthButton CLICKED ");

        if (currentMonth == Calendar.DECEMBER) {
            int currentYear = mCurrentMonth.get(Calendar.YEAR);
            mCurrentMonth.set(Calendar.YEAR, currentYear + 1);
            mCurrentMonth.set(Calendar.MONTH, Calendar.JANUARY);
        } else {
                                currentMonth--;
            mCurrentMonth.set(Calendar.MONTH, currentMonth + 1);
            Log.d(TAG, "currentMonth++ = " + currentMonth + 1);
            Log.d(TAG,
                    "month in next button = "
                            + mCurrentMonth.get(Calendar.MONTH));

        }

        // save the month

        setDateForMonth();

    }

}

here is the code that actually updates the UI. the problem is somwhere in the onClick as it returns the wrong month in the code below:

private void setDateForMonth() {

    monthList.clear();

    Log.d(TAG, ".........setDateForMonth...........");
    Log.d(TAG, "....................");

    Log.d(TAG, "month = " + mCurrentMonth.get(Calendar.MONTH));
    Log.d(TAG, "year = " + mCurrentMonth.get(Calendar.YEAR));

    CalendarMonth[] months = CalendarUtils
            .constructMonthViewArray(mCurrentMonth);

    for (int i = 0; i < months.length; i++) {
        monthList.add(months[i]);
        Log.d(TAG, monthList.get(i).getDay());
    }
    Log.d(TAG, "....................");

    mAdapter = new CalendarMonthAdapter(mContext, monthList);
    mMonthGridView.setAdapter(mAdapter);
    Months[] month = Months.values();

    String currentMonth = month[mCurrentMonth.get(Calendar.MONTH)]
            .toString();
    String year = Integer.toString(mCurrentMonth.get(Calendar.YEAR));
    mMonthLabel.setText(currentMonth + " " + year);

}

private enum Months { January,
February, March, April, May, June,
July, August, September, October,
November, December };

  • 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-05-19T01:29:57+00:00Added an answer on May 19, 2026 at 1:29 am

    Drop java Calendar and move to JodaTime

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an advent calendar for the blog of a friend, and to
Hey guys, I have created a navbar and I'm wondering if I can create
I have created a JTable, the table contains 4 rows, and for a specific
I am using the following code to create calendar controls on textboxes that have
I created a Custom Day Render and I would like to access some custom
I have written a function using javascript for validating a Date selected from a
I've created a category to help me deal with creating dates from year, month,
I have Telerik RadGrid with a custom edit form. In my edit form there
I am writing an app which uses core-data to store my data. Included in

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.