android - Pickers(Time DatePicker)
来源:互联网 发布:不是php集成开发环境 编辑:程序博客网 时间:2024/05/29 03:15
》 Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year). Using these pickers helps ensure that your users can pick a time or date that is valid, formatted correctly, and adjusted to the user's locale.
》We recommend that you use DialogFragment
to host each time or date picker. The DialogFragment
manages the dialog lifecycle for you and allows you to display the pickers in different layout configurations, such as in a basic dialog on handsets or as an embedded part of the layout on large screens.
Although DialogFragment
was first added to the platform in Android 3.0 (API level 11), if your app supports versions of Android older than 3.0—even as low as Android 1.6—you can use the DialogFragment
class that's available in the support library for backward compatibility.
public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current time as the default values for the picker final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity())); } public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Do something with the time chosen by the user }}
Note: If your app supports versions of Android older than 3.0, be sure you've set up your Android project with the support library as described in Setting Up a Project to Use a Library.
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); // Create a new instance of DatePickerDialog and return it return new DatePickerDialog(getActivity(), this, year, month, day); } public void onDateSet(DatePicker view, int year, int month, int day) { // Do something with the date chosen by the user }}》 Caution: If your app supports versions of Android lower than 3.0, be sure that you call
getSupportFragmentManager()
to acquire an instance of FragmentManager
. Also make sure that your activity that displays the time picker extends FragmentActivity
instead of the standard Activity
class.- android - Pickers(Time DatePicker)
- Android控件之Time/DatePicker
- android之Pickers
- Android API Guides---Pickers
- Pickers(选择器)
- Pickers
- android 常用控件 (DatePicker) (TimePicker)
- Android入门之DatePicker(纯java)
- Android基本组件08(DatePicker,TimePicker)
- Android-基本控件(DatePicker 和 TimePicker)
- Android DatePicker OnDateChangedListener不回调(onDateChanged不回调)
- HTML5表单之Input 类型- Date Pickers(日期选择器)
- Pickers(选择器)
- Android DatePicker and TimePicker
- android&&DatePicker&&TimePicker
- android控件19 DatePicker
- Android DatePicker example
- 【Android 开发教程】DatePicker
- python自动化测试(2)-自动化基本技术原理
- error C2440: “static_cast”: 无法从“void (__thiscall CChatDlg::* )(WPARAM,LPARAM)”转换为“LRE
- 计算机技术领域当前的主流技术及其社会需求调查报告
- 感知机实现纯色图片的二分类
- c语言总结
- android - Pickers(Time DatePicker)
- 经典的按键扫描算法
- View动画的特殊使用----LayoutAnimation的使用
- QImage转QPixmap崩溃问题解决
- SpringMVC_RESTful简易笔记
- JSON解析高手
- 拯救大兵雷诺(递归+回溯)
- android开发大牛博客
- hdu 5592 ZYB's Premutation(线段树查询第k大的数)