I am using a DialogFragment to show a DatePicker to choose a date. The point is that such date could be optional, so somewhere i should display a checkbox asking to use the date or not. So how would you do such an UI ?.
So far i tried adding a checkbox on the same DialogFragment but i believe the interaction wont be very intuitive because if you choose the checkbox "no date" i would have to block or disable the datepicker but i wasn't able to do that and even if i do i am not sure if it is the best approach.
Have you seen any application solving a problem like this and how does it solve it ?
Here's how I solved it in my app: make it clear on the button that launches the DialogFragment that a date is optional.
After a date is chosen, add the option to remove it. Clicking on the "x" restores the button to look like above.
Related
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...
Following Android's design guidelines, I ran into this part https://developer.android.com/design/style/metrics-grids.html, where they use a view that I believe is a Spinner in order to show and possibly select the date.
Please guide me in the right directions as I'm not 100% sure this is a Spinner, and also, checking the Calendar app, it seems once you click on it, a DialogFragment pops up, with a single DatePicker (or TimePicker for the hours), but I am not 100% sure of this either.
Thanks in advance
Take a look at the docs, you can specify the Spinner mode. Whether you choose to make it a dialog or dropdown is up to you. Either way, you don't have to worry about setting the value after user has selected it.
http://developer.android.com/reference/android/widget/Spinner.html#MODE_DIALOG
I am getting this from googles calendar, hopefully you can see the image:
When looking specifically at the From and To parts, those look like Spinners, but I could be completely wrong. I would like to do that, essentially what the Calendar in ICS does with Spinners. I put the users date in it, then user clicks and a datepicker pops up. Problem is, I dont see anything that allows me to just set text in it. How can I set it to text without expanding? Thanks in advance.
They don't use a Spinner, but a Button that looks like a Spinner. Take a look to the style.xml files of the app.
For my application, I have to get a date from the user.
I have try a simple EditText with the input type to date, but it's not very convenient for the user who has to enter himself the '/' character.
I have also tried the DatePicker component. It's more convenient than the EditText but it is big compared to others components like EditText.
Is there a best way for a user to get a date ?
Have a button that displays the date and when clicked shows a DatePickerDialog.
I would go with DatePickerDialog that is triggered by "Change" button next to TextView field with currently selected date.
So did you not want to use DatePicker? I'm a bit confused by your problem, since there isn't necessarily a "best" way to get a date, it's based on your preference and situation. If you would like an alternate way to get a date, you could have 3 separate EditText Views that take in the Month, Day and Year and get that information with a "submit" Button or something of that nature. Or you could look into Spinners. Here's and example.
For keyboard entry I normally prefer a maskedit box. If the interface is for touch or mouse you might want to include a drop down calendar.
I have a range say,1-100 and i want the user to select a value from this range.Ofcourse showing this with a spinner will be awful.I want to use the functionality of date widget,where we can pick a date by pressing a +/- sign,the longer the press ,higher the iteration speed.
I found numberpicker.java that has the code the date widget uses to get this functionality, but do i have to paste that entire code to achieve this functionality!
Here is a tutorial on how to pull out NumberPicker; I've followed it myself: http://www.quietlycoding.com/?p=5
I found numberpicker.java that has the
code the date widget uses to get this
functionality, but do i have to paste
that entire code to achieve this
functionality!
Unfortunately, yes, plus perhaps some resources as well (I have not looked at that code recently). I am not aware of anyone who has pulled that out to make a reusable component, and it is not a widget in the SDK.
Sorry!