How to set datePickerMode = "spinner" programmatically?

I need to create a DatePicker program programmatically. And I can not use the xml layout. I know that set spinner in xml datePickerMode="spinner" and then I can use datePicker.setSpinnersShown(true); and datePicker.setCalendarViewShown(false) . I am trying to add an AttributeSet to the constructor, but I do not know how to use it. Can anyone help? How to create a DataPicker in spinner mode?

thanks

+10
source share
3 answers

I already found a message that would describe this problem to you:

I found an explanation in the following post (which describes the problem is very similar to mine):

Problem with Android Inline Datepicker Content

In fact, setCalendarViewShown (false) and setSpinnersShown (true) are apparently no longer working in recent versions.

We must use an explicit XML attribute similar to this Android :. DatePickerMode = "pinwheel"

The problem is that I use DialogFragment without any XML layout (only date picker). Therefore, I cannot set any XML attribute.

The solution is to create a custom custom dialog with the XML layout file using the requested attribute.

FROM: Unable to make my DatePickerDialog programmatically using spinner

Hope this helps

+8
source

If you want to install it programmatically, you can use the code below, but I have not tested this code whether it works or not. Let me know if I can help you with anything.

 datepickerDialog_object.getDatePicker().setSpinnersShown(true); datepickerDialog_object.getDatePicker().setCalendarViewShown(false); 
0
source

This works for me to set the counter mode to DatePickerMode programmatically.

Theme_Holo_Dialog_MinWidth is deprecated

  val dpDialog = DatePickerDialog(activity!!, android.R.style.Theme_Holo_Dialog_MinWidth,listener, year, month, day) dpDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dpDialog.show() 
0
source

Source: https://habr.com/ru/post/982778/


All Articles