CalendarView today date item click

Aleksa picture Aleksa · Oct 24, 2013 · Viewed 17.9k times · Source

I searched a lot on the internet and I couldn't succeed to find correct solution for CalendarView click on today date.

enter image description here

I need to use CalendarView for events app. setOnDateChangeListener works good for other day clicks.

Code:

CalendarView calendarView=(CalendarView) findViewById(R.id.calendarView1);
    calendarView.setOnDateChangeListener(new OnDateChangeListener() {

        @Override
        public void onSelectedDayChange(CalendarView view, int year, int month,
                int dayOfMonth) {
            Intent k = new Intent(GlavnaAktivnost.this, DatumDetalji.class);
            k.putExtra("godina", year);
            k.putExtra("mesec", month);
            k.putExtra("dan", dayOfMonth);
            startActivity(k);

        }
    });

I dont understand well what I need to do and what is the best solution for this? Answers that I was abled to find on stack is to extend CalendarView or bind click on UI but I couldn't find a way with it. Can you give me some example?

Tnx.

Answer

Alexey O. picture Alexey O. · Aug 6, 2015

setOnDateChangeListener will not fire, but OnGlobalLayoutListener will. So if you try:

calendarView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
    @Override
    public void onGlobalLayout(){
    }
});