Is there any way to make DatePickerDialog not dismiss after clicking set button ?
Add an OnClickListener for the dialog button and override onClick.
It would be easier to create your own dialog which uses a DatePicker widget in it. You can find an example of how to use the DatePicker widget in your sdk folder under:
ApiDemos/src/com/example/android/apis/view/DateWidgets1.java
ApiDemos/src/com/example/android/apis/view/DateWidgets2.java
Then you can put whatever buttons and actions you want around the date picker.
Related
When should I use say a DatePickerDialog over a DatePicker widget inflated in a DialogFragment? I've always done it the second way and have no idea when/how to use the first method. The same question applies to other picker widgets like TimePicker and TimePickerDialog as well.
Difference between DatePickerDialog and DatePicker
DatePicker - It is a Control by itself.
DatePickerDialog - It is a dialog with a date picker
When should I use ?
Use DatePicker control in your activity layout (in case you have enough space)
Use the DatePickerDialog when you don't have enough space and/or if you want to open the date dialog in a separate view.
As per the doc, DatePickerDialog is a
A simple dialog containing an DatePicker.
PS. In my experience, I would avoid using it the DatePicker in the activity layout straight away because of space constraints. Consider devices like nexus 4 when you use them.
I want to disable past time numbers in TimePicker. In DatePicker there is a special property for disabling past dates and there is no one for TimePicker so I need to extend an original TimePicker. As I understand I need to change a layout. How to get access to the layout?
Important: android/frameworks/base/core/res/res/layout/time_picker.xml is not an answer - it has got a reference to TimePicker widget where there are no links to other layout files.
Instead of extending a timepicker, extend from dialogfragment and on your onCreateDialog() method return a timepocker dialog. Also remember to implement OnTimeChangedListener so that you can validade the selected date as you need. If you're creating a picker thats gonna be used throughout your whole application you should also consider overriding onDismiss() and then pass the selected date to the activity which started it. Hope this helps
I have a datepicker from here that I have to enable and disable with a button click. I tried:
datepicker.setActivated(false);
datepicker.setEnabled(false);
datepicker.setClickable(false);
datepicker.setFocusable(false);
datepicker.setFocusableInTouchMode(false);
but nothing works. I even tried putting the datepickerdialog inside a layout and put the same settings on the layout but didn't work as well.
Thanks in advance.
Make sure that you declare datepicker object globally bind this datepicker object inside onCreate() using findViewById() method.
I got it to working this way. To disable the datepicker, select the date you want to display and
datePickerView.updateDate(year, month, day);
datePickerView.setMinDate(dateObject.getTime());
datePickerView.setMaxDate(dateObject.getTime());
To enable it back, set it accordingly to default or previous values.
With the DatePickerDialog we can have a fancy interface to set the date as this
(source: androidpeople.com)
I like it but it can only be used to set date so how could I build a "DatePickerDialog-like" AlertDialog?
I mean users could click on the "plus" and "minus" button as well as put in the number with keyboard.
Instead of only being able to select a single date, I'd be able to select three different numbers using the three up/down/scroll controls.
Alright, here you go, check this out. Then, check out Android Custom Dialogs, which would allow you to make your own custom dialog.
Check out this project for more information
Make an EditText field that they can edit with a button to the right which says Pick a Date and pops up a dialog. If the user selects the popup dialog, fill in the EditText with the result.
You can make a custom view with a "+" button, an edittext and a "-" button. Make a custom dialog with that view. Read about Android Custom Dialog. I hope I helped.
I am developing an app for android. I have created a timepickerdialog and a datepickerdialog, but the problem is, both of them run in different dialog boxes, which is not what the way I want my app to work :-S
Is there any way to create a single dialogbox with both time and date picker dialog boxes in it together?
Thx
You can find a DateTimePicker implementation here:
http://code.google.com/p/datetimepicker/
I have created a custom Alert Dialog as in the Google tutorial. I replaced the ImageView and the TextView with a DatePicker and a TimePicker. I changed the following line:
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
with this:
View layout = inflater.inflate(R.layout.dialog_date_time,
(ViewGroup) findViewById(R.id.datePicker));
For whatever reason the first gave an error, but the second worked. Anyway, I can use the two views in the same dialog window now.
call time picker dialog in datepicker's update time method,It'll not be called at the same time but when you press datepicker's set button,Time picker dialog will open . The method is given in the answer of this link:
DateTime picker in android application