i do have one date picker as i just want to make it only can select today's date and future date, no back date. Need some guidelines on how it can be done, maybe spinner can do that?
//start date
TableRow r8 = new TableRow(this);
TextView tvStartDate = new TextView(this);
tvStartDate.setText("Start Date: ");
final EditText etStartDate = new EditText(this);
etStartDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar dateNow = Calendar.getInstance();
int year = dateNow.get(Calendar.YEAR);
int month = dateNow.get(Calendar.MONTH);
int day = dateNow.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dp;
dp = new DatePickerDialog(AddPetActivity.this, new OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
selectedmonth = selectedmonth + 1;
etStartDate.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
}
}, year, month, day);
dp.setTitle("Select Date");
dp.show();
}
});
r8.addView(tvStartDate);
r8.addView(etStartDate);
tb.addView(r8);
You can access the dialog's date picker and set it's min/max dates like so:
dp.getDatePicker().setMinDate(dateNow.getTimeInMillis());
Note that when setting a minimum date for a picker it must be before the selected date of the picker, otherwise you get an IllegalArgumentException
(same goes for max date of course).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.