gpt4 book ai didi

android - 如何在 datepicker android studio 中设置 Activity 日期 tommorow

转载 作者:行者123 更新时间:2023-11-30 00:08:11 25 4
gpt4 key购买 nike

如何在 datepicker android studio 中设置 Activity 日期 tommorow?我将在今天禁用日期,并在明天启用日期?

Calendar cMin = Calendar.getInstance();
Calendar cMax = Calendar.getInstance();

cMax.add(Calendar.DAY_OF_MONTH, 7); //active in 7 days
datePickerDialog.setMinDate(cMin); //active today
datePickerDialog.setMaxDate(cMax); //max active in 7 days

如何禁用今天?

我所有的代码都更详细,但是如果禁用星期日,今天将启用,如何处理这个问题?

public void datePicker(){
final Calendar calendarMax = Calendar.getInstance();
calendarMax.add(Calendar.DAY_OF_MONTH, 7);

final Calendar calendarToday = Calendar.getInstance();
int year = calendarToday.get(Calendar.YEAR);
int month = calendarToday.get(Calendar.MONTH);
calendarToday.add(Calendar.DAY_OF_MONTH, 1);
int day = calendarToday.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(FormTestDrive.this, year, month, day);
datePickerDialog.setMinDate(calendarToday);
datePickerDialog.setMaxDate(calendarMax);

//membuat hari minggu tidak dapat di pilih
List<Calendar> daysList = new LinkedList<>();
Calendar[] daysArray;
Calendar cAux = Calendar.getInstance();

while( cAux.getTimeInMillis() <= calendarMax.getTimeInMillis() ){
//if( cAux.get( Calendar.DAY_OF_WEEK ) != 1 && cAux.get( Calendar.DAY_OF_WEEK ) != 7 ){
if( cAux.get( Calendar.DAY_OF_WEEK ) != Calendar.SUNDAY){
Calendar c = Calendar.getInstance();
c.setTimeInMillis( cAux.getTimeInMillis() );
daysList.add( c);
}
cAux.setTimeInMillis( cAux.getTimeInMillis() + ( 24 * 60 * 60 * 1000 ) );
}
daysArray = new Calendar[ daysList.size() ];
for( int i = 0; i < daysArray.length; i++ ){
daysArray[i] = daysList.get(i);
}
datePickerDialog.setSelectableDays( daysArray );

datePickerDialog.vibrate(true); //vibrate on choosing date?
datePickerDialog.show( getFragmentManager(), "DatePickerDialog" );
}

最佳答案

试试这个:

    final Calendar calendarMax = Calendar.getInstance();
calendarMax.add(Calendar.DAY_OF_MONTH, 7);

final Calendar calendarToday = Calendar.getInstance();
int year = calendarToday.get(Calendar.YEAR);
int month = calendarToday.get(Calendar.MONTH);
calendarToday.add(Calendar.DAY_OF_MONTH, 1);
int day = calendarToday.get(Calendar.DAY_OF_MONTH);


DatePickerDialog datePickerDialog = new DatePickerDialog(DashBoardActivity.this,
null,
year, month, day);
datePickerDialog.getDatePicker().setMinDate(calendarToday.getTimeInMillis());
datePickerDialog.getDatePicker().setMaxDate(calendarMax.getTimeInMillis());
datePickerDialog.show();

O/P

output

希望这对你有帮助...如果你需要任何帮助你可以问

关于android - 如何在 datepicker android studio 中设置 Activity 日期 tommorow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48615980/

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