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
Related
The am and pm buttons in my Time Picker Dialog are not aligned properly. This issue has been bugging me for a while but I am unable to fix it. I tried to insert a time picker widget in my layout instead of using the dialog. But it still has that misalignment bug. My code does not modify the time picker in anyway. I only have a code to take in the inputs and set them inside a textView and nothing more.
This problem does not occur for Android versions below 6.0. Also there seems to be no problem with my mobile as the time picker dialog in other apps works fine and doesn't have this misaligned button problem. It seems like only my app has it.
This is the code inside the listener of the dialog.
TextView set_text = findViewbyId(R.id.TimeSetText);
set_text.setText(hour+":"+minutes);
There is no fault in the rendering of the dialog and the logs don't show any error messages.
This is the image of Time Picker Dialog with misaligned am and pm buttons.
The problem is solved. I didn't notice that time picker has a constructor, which takes a theme to set for the dialog. I noticed it when I was typing the code again in the hopes of solving this problem. So then I created a new style with parent Theme.AppCompat.Light.Dialog with some colors and button styles for customization and it worked.
I no longer have this issue. I guess this issue occurred because my theme for the activity was Material No Action Bar. I don't feel that this was intended though.
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.
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 have some problems in using the date picker from xml layout.
in my app when the user clicks a text view a custom dialog box opens. In the layout of the custom dialog box i am showing a date picker which i have place in my xml file. When it appears in the app i want a particular date to be viewed, for example as 01 Jan 1950. Every time it opens it is showing the present date only.
In my dialog box i have a set and cancel buttons. The Cancel button cancels the dialog box where as when i click the Set button i want the current date to be stored to a String.
In another activity of my app in a custom dialog box i want to show a date picker only with the year columns, i dont need the date and month columns. How to get it, please help me friends
Without seeing any code, I just can propose you to use the method init from the DatePicker class. Check this link but basically, in your activity do something like:
myDatePicker = (DatePicker)findViewByID(...);
myDatePicker.init(myYear,myMonth,myDay, myOnDateChangedListener);
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.