Creating a custom widget Calendar
In android, there is DatePicker and DatePickerDialog. But these two have lot of restrictions. So I decided to create a Calendar widget for one of my Android application.
The features of this calendar are,
- Set the startDate and endDate.
- Set a different color for dates that is coming outside the range of startDate and endDate.
Create two Spinners, one for Month and one for year. Create a TableLayout and add the TextView array, you can use buttons too, its up to you.
Creating spinner and adding values to it is straight forward. For year, from startDate and endDate, create the String array for year. MonthSpinner will be updated when you click on the startYear and endYear.
For creating spinner I created a function as,
public Spinner createSpinner(String[] results) {
Spinner spinner = new Spinner(ctContext);
ArrayAdapter adapter = new ArrayAdapter(ctContext,
android.R.layout.simple_spinner_item, results);
spinner.setAdapter(adapter);
return spinner;
}
Creating the spinner and add values to i…
The features of this calendar are,
- Set the startDate and endDate.
- Set a different color for dates that is coming outside the range of startDate and endDate.
Create two Spinners, one for Month and one for year. Create a TableLayout and add the TextView array, you can use buttons too, its up to you.
Creating spinner and adding values to it is straight forward. For year, from startDate and endDate, create the String array for year. MonthSpinner will be updated when you click on the startYear and endYear.
For creating spinner I created a function as,
public Spinner createSpinner(String[] results) {
Spinner spinner = new Spinner(ctContext);
ArrayAdapter adapter = new ArrayAdapter(ctContext,
android.R.layout.simple_spinner_item, results);
spinner.setAdapter(adapter);
return spinner;
}
Creating the spinner and add values to i…