- #1
fireflies
- 210
- 12
So, I am making an app on Android Studio. It has a date picker on it. The code is
It works well. But as you can see I limited the date picking upto today's date. That is, no future date can be picked. But here arises the problem... that is today's date is December 05, 2017... so, the date picker starts here, since 2018 is not pickable so that place is blank, but there is Jan in months field, and 01 in day's field. That is not pickable. how to make them pickable? So, that the date gets rounded to initial year if I pick any after date? And I want it shows 06 after 5, not 01. like if I select next one, the date should be rounded to 06 January 2017... (Since I am making this app this year, I am creating the starting date from 01 January, 2017- though not coded that part still)...
Any help/link is appreciated :)
Java:
mDisplayDate = (TextView) findViewById(R.id.textSelectDate);
mDisplayDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
java.util.Calendar cal = java.util.Calendar.getInstance();
int year = cal.get(java.util.Calendar.YEAR);
int month = cal.get(java.util.Calendar.MONTH);
int day = cal.get(java.util.Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(OldMemory.this,
android.R.style.Theme_Holo_Light_Dialog_MinWidth,
mDateSetListener,
year,month,day);
dialog.getDatePicker().setMaxDate(System.currentTimeMillis());
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});
mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
String Month=NULL;
Log.d(TAG, "onDateSet: dd/mm/yyyy: "+dayOfMonth+" " +month+", "+year);
if(month==0)
Month="January";
else if(month==1)
Month="February";
else if(month==2)
Month="March";
else if(month==3)
Month="April";
else if(month==4)
Month="May";
else if(month==5)
Month="June";
else if(month==6)
Month="July";
else if(month==7)
Month="August";
else if(month==8)
Month="September";
else if(month==9)
Month="October";
else if(month==10)
Month="November";
else if(month==11)
Month="December";
Date = dayOfMonth+" " +Month+", "+year;
mDisplayDate.setText(Date);
}
};
It works well. But as you can see I limited the date picking upto today's date. That is, no future date can be picked. But here arises the problem... that is today's date is December 05, 2017... so, the date picker starts here, since 2018 is not pickable so that place is blank, but there is Jan in months field, and 01 in day's field. That is not pickable. how to make them pickable? So, that the date gets rounded to initial year if I pick any after date? And I want it shows 06 after 5, not 01. like if I select next one, the date should be rounded to 06 January 2017... (Since I am making this app this year, I am creating the starting date from 01 January, 2017- though not coded that part still)...
Any help/link is appreciated :)