Disabling DatePickerDialog - android

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.

Related

How to enable setCalendarViewShown or disable calendar in datepicker post API 24

I have a project where I use datepicker for the user to confirm a date
When the user selects confirm I wish to disable the datepicker so that they can't use it again
Unfortunatelly when I do something like this:
((DatePicker)findViewById(R.id.datepicker)).enabled = false;
only the spinner part gets disabled while the calendar can still be touched and used to alter the spinner
the only solution I found is using setCalendarViewShown(false) when the user confirms and then disabling the picker
unfortunatelly this seems to be deprecated so I wish to find some way to replace it
So my question is this
Is there a way to programmatically either disable ALL parts of the DatePicker or hide the calendar?
I know it can be done through xml but I wish to use it in code
Thanks in advance for any help you can provide
You can hide the datepicker with:
datepicker.setVisibility(View.INVISIBLE);
An option that you can choose to disabled all dates less one, is combine this two lines.
datepicker.setMinDate
datepicker.setMaxDate
So after the user pick one date, set the date like the min and the max of the calendar, and with this way, the user will not be able to choose a new one.
Something like:
datepicker.setMinDate(theDatePickedByUser)
datepicker.setMaxDate(theDatePickedByUser)
It should work...

Android: Customizing Calendar View style to show weekview

I created a view that has CalendarView added programatically.
Code:
CalendarView calendarView = new CalendarView(context);
calendarView.setDate(new Date().getTime());
cardInner.addView(calendarView);
http://www.screencast.com/t/ugGKqI2V0EH
The current set up is the one on the screenshot. I was wondering if there is a way to make it look this way?
http://screencast.com/t/Q1kwyib0hOv
This is not possible using the CalendarView widget from AOSP. See https://developer.android.com/reference/android/widget/CalendarView.html
It is however possible to prevent the user from picking any date other than a date inside a certain week. You can achieve this by using the setMinDate and setMaxDate methods: https://developer.android.com/reference/android/widget/CalendarView.html#setMaxDate(long)
A third option would be extending the CalendarView widget and altering the onDraw method to only draw one row.
Also, try and search around on google. There might be a 3rd party library that can already do this.

When to use DatePickerDialog over a DatePicker in a DialogFragment?

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.

How to extend TimePicker widget?

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

android DatePickerDialog

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.

Categories

Resources