编程语言
首页 > 编程语言> > java – 在android中禁用日历视图中的每个星期日

java – 在android中禁用日历视图中的每个星期日

作者:互联网

如何在以下代码中仅禁用星期日?
我们找不到任何解决方案来禁用一个月的星期日

MainActivity.java

CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
Calendar calendar = Calendar.getInstance();
calendarView.setMinDate(calendar.getTimeInMillis());
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() 
{

    @Override
    public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
        Toast.makeText(getApplicationContext(), "" + dayOfMonth, 0).show();// TODO Auto-generated method stub`enter code here`

    }
});

解决方法:

我在一个项目中使用了这段代码.看看它是否产生了理想的结果 –

//Global Variables
private Calendar lastSelectedCalendar = null;
private CalendarView calendarView;
//

calendarView = (CalendarView) findViewById(R.id.calendarView);
lastSelectedCalendar = Calendar.getInstance();
calendarView.setMinDate(lastSelectedCalendar.getTimeInMillis() - 1000);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

    @Override
    public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
        Calendar checkCalendar = Calendar.getInstance();
        checkCalendar.set(year, month, dayOfMonth);
        if(checkCalendar.equals(lastSelectedCalendar))
            return;
        if(checkCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
            calendarView.setDate(lastSelectedCalendar.getTimeInMillis());
        else
            lastSelectedCalendar = checkCalendar;
    }
});

标签:java,android,android-calendar
来源: https://codeday.me/bug/20190705/1388892.html