日期、時間選擇對話方塊
阿新 • • 發佈:2018-12-27
日期
/** * 選擇日期 */ private void selectData() { new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String date=String.format("%d-%d-%d", year,monthOfYear+1,dayOfMonth); tv_data.setText(date); } },2017, 5, 13).show(); }
時間
/** * 選擇時間 */ private void selectTime() { new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String time = String.format("%d:%d", hourOfDay, minute); tv_time.setText(time); } },9,5,true).show(); }