Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CalendarView today date item click

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.

like image 317
Aleksa Avatar asked Oct 24 '13 10:10

Aleksa


1 Answers

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

calendarView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
    @Override
    public void onGlobalLayout(){
    }
});
like image 154
Alexey O. Avatar answered Oct 06 '22 00:10

Alexey O.