Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

That was introduced around API version 21. If you MinSDK is lower you won't have visibility to that feature.

However I just tested this by creating a sample project from scratch setting the min/max SDK to 22 and I still don't have visibility to that method. Potentially this is a bug in Android Studio.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...