Android Date Time picker in one dialog

后端 未结 9 1192
抹茶落季
抹茶落季 2021-02-07 01:31

I am using material Date Time picker for my Android app. But I want to combine the Date and Time picker in one dialog.

<
9条回答
  •  孤城傲影
    2021-02-07 02:18

    If you need to select the time right after the date selection you can simply show TimePickerDialog automatically after date is selected. This is the easiest way.

    While you have listener that is fired when date is selected with selected date, you can simply pass that selected date to TimePickerDialog and with a few customization in mdtp_time_picker_dialog.xml you can add a TextView to show the selected text.

    Another option is merging mdtp_time_picker_dialog.xml and mdtp_date_picker_dialog.xml that are root layouts for date picker dialog and time picker dialog. You can set time picker part visibility as GONE and switch the visibility when you want to switch pickers.

    The second solution is more difficult to implement because in addition to layouts, you have to merge all controls and listeners.

    If you want the user to see both of the pickers, I think you actually need to design a new view yourself. That library layouts is not suitable for this.

提交回复
热议问题