1

我需要实施setOnClickListenerCalendarView但它不起作用,因为CalendarView有一个subview或类似的东西。我试过了:

calendarView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });

但它不起作用

拜托,有人知道我该如何实施吗?

谢谢

4

1 回答 1

1
    private int mYear;
    private int mMonth;
    private int mDay;    
    static final int DATE_PICKER_ID = 1111;
final Calendar c = Calendar.getInstance();
       mYear  = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay   = c.get(Calendar.DAY_OF_MONTH);


calenderView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                showDialog(DATE_PICKER_ID);
            }
        });     


@Override
    protected Dialog onCreateDialog(int id) {
       switch (id) {

  case DATE_PICKER_ID:

// set date picker as current date

   return new DatePickerDialog(this, pickerListener , mYear, mMonth,mDay );

}

return null;

    }

    private DatePickerDialog.OnDateSetListener pickerListener = new DatePickerDialog.OnDateSetListener() {

        // when dialog box is closed, below method will be called.
        @Override
        public void onDateSet(DatePicker view, int selectedYear,
                int selectedMonth, int selectedDay) {
            mDay = selectedDay;
            mMonth = selectedMonth;
            mYear = selectedYear;
            Calendar c = Calendar.getInstance();
            c.set(mYear, mMonth, mDay);
            SimpleDateFormat df = new SimpleDateFormat("MMM-dd-yyyy");
            String selectedDate = df.format(c.getTime());
            calenderView.setText(selectedDate);         
           }
        };
于 2013-10-25T09:39:55.853 回答