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);
See the Android Developers guide To get the current year, month and days you’d use the following:
Alternatively, you can use
SimpleDateFormatlike so:The other way around also works: