Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highlighting specific date in calendar view without onClickListener

Is there a good way to highlight a specific/different dates as I want on calendar view in android? Thanks!

like image 619
Dexter Wong Avatar asked Nov 09 '22 13:11

Dexter Wong


1 Answers

private void setCustomResourceForDates() {

        Calendar cal = Calendar.getInstance();
        //highlighlighting the holidays in a month taking the static dates
        ArrayList<String> dates = new ArrayList<String>();
        dates.add("02-08-2015");
        dates.add("22-08-2015");
        dates.add("17-09-2015");
        dates.add("25-09-2015");
        dates.add("27-09-2015");
        dates.add("13-10-2015");
        dates.add("22-10-2015");
        SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
        Date date = new Date();
        for (int i = 1; i < dates.size(); i++) {
            inputString2 = dates.get(i);
            inputString1 = myFormat.format(date);

            try {
                //Converting String format to date format
                date1 = myFormat.parse(inputString1);
                date2 = myFormat.parse(inputString2);
                //Calculating number of days from two dates
                long diff = date2.getTime() - date1.getTime();
                long datee = diff / (1000 * 60 * 60 * 24);
                //Converting long type to int type
                day = (int) datee;
            } catch (ParseException e) {
                e.printStackTrace();
            }
            cal = Calendar.getInstance();
            cal.add(Calendar.DATE, day);
            holidayDay = cal.getTime();
            colors();

        }
    }

    public void colors() {
        if (caldroidFragment != null) {
            caldroidFragment.setBackgroundResourceForDate(R.color.green,
                    holidayDay);
            caldroidFragment.setTextColorForDate(R.color.white, holidayDay);
        }
    }
}

call setCustomResourceForDates(); on onCreate method (in Caldroid Calendar).

like image 179
Jagat Bandhu Sahoo Avatar answered Nov 14 '22 22:11

Jagat Bandhu Sahoo