如何禁用日历中的前一个月?

时间:2019-05-14 04:44:08

标签: android time calendar visibility

我想打开日历对话框以显示所有月份禁用日历后的一个月后的未来,该怎么做。我附上了下面的代码。

@SuppressLint("NewApi")
private void carryfwddate() {
    carryfwddate = view.findViewById(R.id.carryfwddate);
    carryfwddate.setShowSoftInputOnFocus(false);
    final DatePickerDialog.OnDateSetListener date = new
            DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear,
                                      int dayOfMonth) {
                    // TODO Auto-generated method stub
                    carryfwdCalendar.set(Calendar.YEAR, year);
                    carryfwdCalendar.set(Calendar.MONTH, monthOfYear);
                    carryfwdCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    carrydate();
                }
            };
    carryfwddate.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                new DatePickerDialog(getActivity(), date, carryfwdCalendar
                        .get(Calendar.YEAR), carryfwdCalendar.get(Calendar.MONTH),
                        carryfwdCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }
            return false;
        }
    });
}

private void carrydate() {
    String myFormat = "yyyy-MM-dd";
    SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
    carryfwddate.setText(sdf.format(carryfwdCalendar.getTime()));

}

0 个答案:

没有答案