Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get selected date in CalenderView in Android?

Tags:

android

mobile

Calendar date = Calendar.getInstance();     
SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");

curDate = sdf.format(date.getTime());

I have done the above code inside onCreate method. But it can only return the current date. What I want is to have the date selected in the calender.

<CalendarView
      android:id="@+id/calendarView1"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

Please help me

like image 560
Ravindu Avatar asked Dec 08 '22 16:12

Ravindu


1 Answers

I used CalendarView instead of Calender and it's working now.

calendarView.setOnDateChangeListener(new OnDateChangeListener() {

                @Override
                public void onSelectedDayChange(CalendarView view, int year, int month,
                        int dayOfMonth) {
                    curDate = String.valueOf(dayOfMonth);
                }
            });
like image 147
Ravindu Avatar answered Dec 11 '22 06:12

Ravindu