gpt4 book ai didi

java - 在android的日历 View 中禁用每个星期日

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:11:26 25 4
gpt4 key购买 nike

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

主要 Activity .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的日历 View 中禁用每个星期日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49635732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com