I have a list of dates that I want to color in red on calendarview . how can I do ?
my activity..
public class Calendario extends Activity {
RelativeLayout rl;
final Calendar calendar = Calendar.getInstance();
CalendarView cal;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendar);
rl = (RelativeLayout) findViewById(R.id.rl);
cal = new CalendarView(Calendario.this);
rl.addView(cal);
cal.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {
// TODO Auto-generated method stub
}
});
}
}
What code i've to add in order to color a date ?
Your best bet might be to create your own CalendarView class i.e. CalendarViewCustom based on the source code found here.
You could then add an extra method to the LegacyCalendarViewDelegate class similar to the setFocusedMonthDateColor() method to iterate through the weeks and set a date and colour in the WeekView class (might be worth storing these key/value date/colours as an Map collection instance variable in the WeekView class). e.g.
The above method then needs to be exposed by adding another method to the parent class CalendarViewCustom (similar to its existing methods) which can then be called on an instance of the class i.e.
All you need to do then is draw the listed colours on the canvas in the WeekView class method called drawWeekNumbersAndDates() for the specified dates using the existing for loop ( for (; i < nDays; i++) ) and iterate over the Map and change the paint colour for the date text i.e. mMonthNumDrawPaint.setColor().
Hope this points you in the right direction.