安卓 Pickers(选择器)
概述
DialogFragment 来容纳每一个时间或日期选择器。DialogFragment 为你管理对话框的生命周期并且允许你在不同的布局结构中显示该选择器,例如 手机中的基本对话框或在大屏幕中作为一部分嵌入。minSdkVersion 是11或之上,你可以直接使用DialogFragment.。创建一个时间选择器
将 DialogFragment延伸为时间选择器(time picker)
DialogFragment ,你必须:- 定义
onCreateDialog()来返回一个TimePickerDialog的引用 - 实现
TimePickerDialog.OnTimeSetListener接口来响应用户设置时间的事件
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 }}展示时间选择器
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pick_time" android:onClick="showTimePickerDialog" />public void showTimePickerDialog(View v) { DialogFragment newFragment = new TimePickerFragment(); newFragment.show(getSupportFragmentManager(), "timePicker");}getSupportFragmentManager() 时获得了一个FragmentManager.的引用。也应该确保你展示该时间选择器的activity继承了FragmentActivity而不是标准的Activity 类。创建日期选择器(Date Picker)
TimePickerDialog.)相似。唯一的不同将在于为对话框创建的fragment。DatePickerDialog ,你需要定义一个继承自DialogFragment 的fragment类并且从fragment中的onCreateDialog()方法中返回一个DatePickerDialog将DialogFragment 延伸为日期选择器(date picker)
- 定义一个
onCreateDialog()方法返回一个DatePickerDialog的引用 - 实现DatePickerDialog.OnDateSetListener接口来接收用户选择日期的事件
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 }}展示日期选择器
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pick_date" android:onClick="showDatePickerDialog" />public void showDatePickerDialog(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker");}getSupportFragmentManager() 时获得了一个FragmentManager.的引用。也应该确保你展示该时间选择器的activity继承了FragmentActivity而不是标准的Activity 类。安卓 Pickers(选择器)的更多相关文章
- 安卓 Dialogs(对话框)
转载自:http://www.apkbus.com/home.php?mod=space&uid=679028&do=blog&id=61197 对话框是一个小的窗口用以提示用 ...
- Android常用控件及对应Robotium API
最近发现Android控件不熟悉,看Robotium的API都费劲. 常用Android控件: 控件类型 描述 相关类 Button 按钮,可以被用户按下或点击,以执行⼀个动作 Button Text ...
- react-native 插件汇总
部分自己搜集 部分 来自别的网站 第三方路由插件 react-native-router-flux react-native-scrollable-tab-view 选项卡 测滑动菜单 react-n ...
- 安卓自动化测试,贺晓聪之uiautomator设备和选择器~Python详解
1.设备对象 引入uiautomator,获取设备对象<所谓设备对象可理解为:Android模拟器或者真机> 语法:from uiautomator import device as d ...
- 安卓开发笔记(二十八):仿写IOS switch选择器控件实现,checkbox
我们先来看看效果: 这里我们主要使用了github上的一个开源项目,配置起来比较方便,下面解释一下该如何使用:首先是:Gradle文件当中进行配置: dependencies { implementa ...
- 安卓开发_浅谈DatePicker(日期选择器)
DatePicker继承自FrameLayout类,日期选择控件的主要功能是向用户提供包含年.月.日的日期数据并允许用户对其修改.如果要捕获用户修改日期选择控件中的数据事件,需要为DatePicker ...
- 安卓开发_浅谈TimePicker(时间选择器)
TimePicker也继承自FrameLayout类.时间选择控件向用户显示一天中的时间(可以为24小时,也可以为AM/PM制),并允许用户进行选择.如果要捕获用户修改时间数据的事件,便需要为Time ...
- HTML5表单之Input 类型- Date Pickers(日期选择器)
HTML5 拥有多个可供选取日期和时间的新输入类型: date-选取日.月.年 month-选取月.年 week-选取周和年 time-选取时间(小时和分钟) datetime-选取时间.日.月.年( ...
- 微信小程序中利用时间选择器和js无计算实现定时器(将字符串或秒数转换成倒计时)
转载注明出处 改成了一个单独的js文件,并修改代码增加了通用性,点击这里查看 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时 ...
随机推荐
- Integral类型的跨平台使用
fundamental integral types or extended integral types 我们先通过下图,来了解可以跨平台使用的整数类型: 之所以我们需要以上各种明确指定宽度的int ...
- CDOJ 1259 昊昊爱运动 II 线段树+bitset
昊昊爱运动 II 昊昊喜欢运动 他N天内会参加M种运动(每种运动用一个[1,m]的整数表示) 现在有Q个操作,操作描述如下 昊昊把第l天到第r天的运动全部换成了x(x∈[1,m]) 问昊昊第l天到第r ...
- 深入理解Windows X64调试
随着64位操作系统的普及,都开始大力进军x64,X64下的调试机制也发生了改变,与x86相比,添加了许多自己的新特性,之前学习了Windows x64的调试机制,这里本着“拿来主义”的原则与大家分享. ...
- eclipse引入tomcat
1.默认大家的tomcat都已经安装好了,这里打开eclipse,选择windows,下面的属性(preference). 2.进入到属性配置页,选择server -- runtime Envi ...
- AssemblyInfo.cs文件参数具体讲解
在asp.net中有一个配置文件AssemblyInfo.cs主要用来设定生成的有关程序集的常规信息dll文件的一些参数,下面是默认的AssemblyInfo.cs文件的内容具体介绍 //是否符合公共 ...
- Linux:-bash: ***: command not found
Linux:-bash: ***: command not found,系统很多命令都用不了,均提示没有此命令. 突然之间linux很多命令都用不了,均提示没有此命令. 这应该是系统环境变量出现了问题 ...
- Python概述_软件安装_常见问题
1. Python安装 目前python有2个大版本,2和3,由于2和3语法有差别,现有的许多库都是基于python2开发,本系列文章以python2为主. 1.1 重要概念 1. 动态语言 运行 ...
- Java多线程-线程的调度(守护线程)
本文转自http://www.cnblogs.com/linjiqin/p/3210004.html 感谢作者 守护线程与普通线程写法上基本没啥区别,调用线程对象的方法setDaemon(true), ...
- iOS Architecture
目前ios的指令集有以下几种: armv6 iPhone iPhone2 iPhone3G 第一代和第二代iPod Touch armv7 iPhone4 iPhone4S armv7s iPhone ...
- POJ3176——Cow Bowling(动态规划)
Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ...