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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:33:50+00:00 2026-05-31T09:33:50+00:00

I have created an xml layout which is in effect a grid. I need

  • 0

I have created an xml layout which is in effect a grid. I need to use it as a calendar and have read about the calendar class but i’ve been unable to get any of the code it suggests to work.

How would i go about displaying the current year,month and days in the various text views?

This is what i have so far:

Calendar c = Calendar.getInstance(); 
    int month = c.get(Calendar.MONTH);

    String month_name = Integer.toString(month);

    TextView monthdisp = (TextView) findViewById(R.id.month_disp);

    monthdisp.setText(month_name);

    setContentView(R.layout.main);

However a null pointer excpetion is generated at monthdisp.setText(month_name);

  • 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-31T09:33:51+00:00Added an answer on May 31, 2026 at 9:33 am

    See the Android Developers guide To get the current year, month and days you’d use the following:

    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR); // get the current year
    int month = cal.get(Calendar.MONTH); // month...
    int day = cal.get(Calendar.DAY_OF_MONTH); // current day in the month
    
    // sets your textview to e.g. 2012/03/15 for today
    textview.setText("Year / month / day: "+ year + "/" + month + "/" + day);
    

    Alternatively, you can use SimpleDateFormat like so:

    // set-up the desired formatting
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    
    Date now = cal.getTime(); // set the current datetime in a Date-object
    
    // SimpleDateFormat.format( Date date ) returns a formatted string
    // with the predefined format
    String mTimeString = sdf.format( now ); // contains yyyy-MM-dd (e.g. 2012-03-15 for March 15, 2012)
    
    TextView textView = new TextView(this);
    textView.setText( mTimeString );
    

    The other way around also works:

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    
    String mDateString = "14-05-2012";
    Date mDate = sdf.parse( mDateString ); // returns a Date-object
                                           // with date set to May 14, 2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a xslt document which formats an xml document, but I would
In ViewPagerAdapter.class I have 2 layout(whereami.xml and mapview.xml), and use LayoutInflater to inflate each
I have created XML file,but I can't view it/output it.I know there is no
I have created a XML image gallery, which displays text in between each slide.
Using WiX (Windows Installer XML) I have created an MSI installer which installs Word
I have created a custom tab layout which look like this,I want to make
I want to use a list view and I have created my own layout
I have created a class (InputControl) which extends the view of my main class
Context: I have a TableLayout (created using XML), which has one TableRow, which has
I have created an XML schema (foo.xsd) and used xjc to create my binding

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.