Android 日期控件选择

DatePickerDialog.OnDateSetListener startDatePickListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker arg0, int year, int month, int day) {
            Date endDate = new Date();
            Date startDate = new Date();
            String str = year + "-" + (++month) + "-" + day;
            String strDate;
            TextView tvEndDate = (TextView) queryOutPlanWind.getItemView(R.id.tvEndDate);
            TextView tvStartDate = (TextView) queryOutPlanWind.getItemView(R.id.tvStartDate);
            try {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                endDate = (Date) formatter.parse(tvEndDate.getText().toString());
                startDate = (Date) formatter.parse(str);
                strDate=formatter.format(startDate);
            } catch (Exception e) {
            }
            if (endDate.compareTo(startDate) < 0) {
                Toast.makeText(OutPlanActivity.this, "开始日期不能大于结束日期!", Toast.LENGTH_LONG).show();
                tvStartDate.setText(tvEndDate.getText());
            } else {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                strDate=formatter.format(startDate);
                tvStartDate.setText(strDate);
            }
        }
    };

你可能感兴趣的:(Android 日期控件选择)