Date Picker with max and minimum date in onDateChanged() in Android 1.5?

前端 未结 1 662
失恋的感觉
失恋的感觉 2021-01-03 08:36

I am working on DatePicker in android 1.5. I am trying to set Maximum and minimum date.Minimum date should be the current date and maximum date should be the date which I wi

相关标签:
1条回答
  • 2021-01-03 09:11

    This way, i solved my problem

    DateDP.init(minYear, minMonth, minDay, new OnDateChangedListener()
        {
    
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth)
        { 
                if (year > maxYear ||monthOfYear > maxMonth && year == maxYear||
                     dayOfMonth > maxDay && year == maxYear && monthOfYear == maxMonth){
                // Toast.makeText(DatePickerActivity.this,"max year", Toast.LENGTH_SHORT).show();
    
                view.updateDate(maxYear, maxMonth, maxDay);
    
                dateOutput = String.format("%04d-%02d-%02d", 
                     maxYear, maxMonth+1, maxDay);
               //Toast.makeText(DatePickerActivity.this,"maxYear  "+dateOutput, Toast.LENGTH_SHORT).show();
    
                }else if(year < minYear ||monthOfYear < minMonth && year == minYear||
                     dayOfMonth < minDay && year == minYear && monthOfYear == minMonth){
    
    
                //Toast.makeText(DatePickerActivity.this,"min year", Toast.LENGTH_SHORT).show();
    
                 view.updateDate(minYear, minMonth, minDay );
    
                dateOutput = String.format("%04d-%02d-%02d", 
                        minYear, minMonth+1, minDay);
    
                     //Toast.makeText(ManageShowing.this,dateOutput, Toast.LENGTH_SHORT).show();                              
    
                }else{
    
                 //Toast.makeText(ManageShowing.this,"else", Toast.LENGTH_SHORT).show();
    
                 dateOutput = String.format("%04d-%02d-%02d", 
                         year, monthOfYear+1, dayOfMonth);
    
                        // Toast.makeText(ManageShowing.this,dateOutput, Toast.LENGTH_SHORT).show();                     
    
                }
                mDateDisplay.setText(dateOutput);
    
        }}); // DateDP.init()
    
    0 讨论(0)
提交回复
热议问题