I have a DatePicker
in my app which is set in this way :
Layout :
<TextView
android:id="@+id/traveltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.11"
android:text="Date Of Travel"
android:textStyle="bold" />
<EditText
android:id="@+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<Button
android:id="@+id/btnCalendar"
android:layout_width="30dp"
android:layout_height="42dp"
android:layout_marginRight="50dp"
android:background="@drawable/date" >
</Button>
</LinearLayout>
Global Values :
Button btnCalendar;
EditText txtDate;
private int mYear, mMonth, mDay;
OnCreate :
btnCalendar = (Button) findViewById(R.id.btnCalendar);
txtDate = (EditText) findViewById(R.id.txtDate);
btnCalendar.setOnClickListener(this);
Method :
@Override
public void onClick(View v) {
if (v == btnCalendar) {
// Process to get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
// Launch Date Picker Dialog
DatePickerDialog dpd = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
// Display Selected date in textbox
txtDate.setText(dayOfMonth + "-"
+ (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
dpd.show();
} }
Now my question is, how do i disable the PREVIOUS dates based on the CURRENT date?
Please help. Thanks.
In your onDateSet you can validation on date like you want to set date only after today's date then add the following code in onDateSet method
hope this will work for you
// Method automatically gets Called when you call
showDialog()
methodonly use use the for calling dialog showDialog(1);
Try this:
Simply try this solution:
etDateOfDelivery.setOnClickListener(new OnClickListener() {
I don't think you can actually disable the date picker. But once the date is selected, you can validate it with current date and make the user reselect future date. You can send a toast message if the user selects the past date.