Android UI日期时间选择之DateTimePicker
程序员文章站
2022-05-01 09:39:29
...
这个DateTimePicker提供了Google Agenda app的日期时间选择器,非常漂亮。
https://github.com/flavienlaurent/datetimepicker
***依赖于NineOldAndroids https://github.com/JakeWharton/NineOldAndroids
日期选择:
选择小时:
选择分钟:
https://github.com/flavienlaurent/datetimepicker
***依赖于NineOldAndroids https://github.com/JakeWharton/NineOldAndroids
import com.fourmob.datetimepicker.date.DatePickerDialog; import com.fourmob.datetimepicker.date.DatePickerDialog.OnDateSetListener; import com.sleepbot.datetimepicker.time.RadialPickerLayout; import com.sleepbot.datetimepicker.time.TimePickerDialog; public class MainActivity extends FragmentActivity implements OnDateSetListener, TimePickerDialog.OnTimeSetListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_date_time_picker_sample); final Calendar calendar = Calendar.getInstance(); final DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), false); final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY) ,calendar.get(Calendar.MINUTE), false, false); findViewById(R.id.button_date).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { datePickerDialog.show(getSupportFragmentManager(), "datepicker"); } }); findViewById(R.id.button_time).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { timePickerDialog.show(getSupportFragmentManager(), "timepicker"); } }); } @Override public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { ((TextView) findViewById(R.id.date_text)).setText(year + "/" + (month + 1) + "/" + day); } @Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) { ((TextView) findViewById(R.id.time_text)).setText(hourOfDay + ":" + minute); } }
日期选择:
选择小时:
选择分钟:
上一篇: 二维数组
推荐阅读
-
Android 自定义日期段选择控件功能(开始时间-结束时间)
-
Android仿iPhone日期时间选择器详解
-
Android开发之DatePickerDialog、TimePickerDialog时间日期对话框用法示例
-
Android开发之DatePicker和TimePicker实现选择日期时间功能示例
-
Android之日期及时间选择对话框用法实例分析
-
详解element-ui日期时间选择器的日期格式化问题
-
Element DateTimePicker日期时间选择器的使用示例
-
element-ui 时间日期选择器格式化后台需要的格式
-
element-ui 日期选择器范围时间限制
-
boostrap的日期选择:datetimepicker 做 开始时间与 结束时间的判断,开始时间小于结束时间