How to create a TimePicker when you click on the button in Fragment?
1 answer
The easiest thing is to search the library on GitHub and use it. For example this - SlideDateTimePicker
- Download libu
- Put the folder with it in the root of the project
- We connect to the project in the gradle:
dependencies { compile project(':slideDateTimePicker') } 4. Create a listener
SlideDateTimeListener listener = new SlideDateTimeListener() { @Override public void onDateTimeSet(Date date) { // Do something with the date. This Date object contains // the date and time that the user has selected. } @Override public void onDateTimeCancel() { // Overriding onDateTimeCancel() is optional. } }; - Show dialogue
new SlideDateTimePicker.Builder(getSupportFragmentManager()) .setListener(listener) .setInitialDate(new Date()) .build() .show(); Personally, I like this one better: MaterialDateTimePicker
- when calling a piker from a fragment there are nuances (see my answer to a similar question in the commentary under the question), there is also a button in the question .. - pavlofff
- @pavlofff, read the answer, but did not find any nuances ( - Yuriy SPb ♦
- There is a problem with the standard implementation of pickers - they look different on different versions of the OS. And if the designer sees this - he will be furious) - YuriySPb ♦
- Yuri, I would be grateful if you could help me create a TimePicker and write a manual for your MaterialDateTimePicker. The key point here is that I call the TimePicker from Framgment - Martinez Toni
- @MartinezToni, there is no difference where to call. What exactly you can not? In the description there is a manual and there is also an example application - YuriySPb ♦
|
DatePicker, but the difference is minimal. - pavlofff