简体   繁体   中英

Date Picker in Android

I want to display a date picker for selecting date of birth,so as to user restricted to choose future date.currently date picker displays all dates including future also.i want to show the dates up to current dates only. Thanks.

Use the setMaxDate function, and set that to the current date

    Datepicker dp = (DatePicker) v.findViewById(R.id.date_picker);
    // Set it to only show past dates...
    dp.setMaxDate(System.currentTimeMillis());

( reference )

I recommend the Date Picker Dialog ? Then just extend it to fit your requirements.

It's some what hard to explain how to create a Date Picker. What's better is looking at the sample code from the Android API Demos which shows you how to do a Date Picket and much more. You can figure out how to download these API Demos at: http://developer.android.com/resources/samples/get.html . Good luck!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM