So I'm practicing getting the hang of android studio by making simple programs. I have created a calendar using the calendarview api and the code is:
package com.try.androidcalendarviewexample;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.CalendarView.OnDateChangeListener;
import android.widget.Toast;
import android.app.Activity;
public class AndroidCalendarviewExample extends Activity {
CalendarView calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//sets the main layout of the activity
setContentView(R.layout.activity_main);
//initializes the calendarview
initializeCalendar();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void initializeCalendar() {
calendar = (CalendarView) findViewById(R.id.calendar);
// sets whether to show the week number.
calendar.setShowWeekNumber(false);
// sets the first day of week according to Calendar.
// here we set Monday as the first day of the Calendar
calendar.setFirstDayOfWeek(2);
//The background color for the selected week.
calendar.setSelectedWeekBackgroundColor(getResources().getColor(R.color.green));
//sets the color for the dates of an unfocused month.
calendar.setUnfocusedMonthDateColor(getResources().getColor(R.color.transparent));
//sets the color for the separator line between weeks.
calendar.setWeekSeparatorLineColor(getResources().getColor(R.color.transparent));
//sets the color for the vertical bar shown at the beginning and at the end of the selected date.
calendar.setSelectedDateVerticalBar(R.color.darkgreen);
//sets the listener to be notified upon selected date change.
calendar.setOnDateChangeListener(new OnDateChangeListener() {
//show the selected date as a toast
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int day) {
Toast.makeText(getApplicationContext(), day + "/" + month + "/" + year, Toast.LENGTH_LONG).show();
}
});
}
}
Currently this just displays the a simple calendar view full screen and lets you scroll down through the months. I was wondering how I may add events to this code. Is there any simple API that could be used to extend this calendar to holding events too? Or should I be using something else for that
0 comments:
Post a Comment