I have a simple DatePickerFragment that extends DialogFragment. I'm wanting to set a validation callback so I can prevent "OK" being selected if an invalid date is picked. I first tried setMaxDate and that grays out the invalid choices but still allows them to be selected and OK to be pressed. So I was hoping setting the validation callback would be the solution.
abstract public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
public DatePickerDialog datePickerDialog;
// public DatePickerFragment() {
//
// }
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
datePickerDialog = new DatePickerDialog(getActivity(), this, year, month, day);
DatePicker datePicker = datePickerDialog.getDatePicker();
datePicker.setMaxDate(c.getTimeInMillis());
// this won't resolve!
datePicker.setValidationCallback( xxx );
return datePickerDialog;
}
}
I cannot figure out why I can't access or reference android.widget.DatePicker.ValidationCallback or any of the related bits in my code. If I hit CTRL+B to look at DatePickerDialog I can see it imports it and references these fields. Everything appears to be public. But I can't even get the import to resolve. What could be wrong? This is a brand new install of the latest Android Studio and my gradle file looks like this:
dependencies {
// Include local libraries
compile fileTree(dir: 'libs', include: ['*.jar'])
// Android support libraries
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:support-v13:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.1.1'
}
The path of the DatePickerDialog.java that Android Studio takes me to is E:srcAndroidsdksourcesandroid-22androidappDatePickerDialog.java. That combined with the gradle settings leads me to believe everything I'm looking at should all be API 22... I'm at total loss here. Any ideas?
Thanks!
See Question&Answers more detail:os