安卓 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文件,并修改代码增加了通用性,点击这里查看 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时 ...
随机推荐
- spring_150802_resource
接口Service: package com.spring.service; public interface DogPetService { public void queryAllDogPets( ...
- http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html
http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html
- const以及入栈出栈
#include "stdafx.h"#include <iostream>using namespace std; class StringStack{ enum{s ...
- Spring学习总结(2)——Spring IOC的前世今生
前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...
- 本地替换文件读取MYSQL密码
Mysql 的密码默认是存储在/data/mysql/下面的三个文件中:user.MYD,user.frm,user.MYI 先把这三个文件下载到本地,然后替换本地的这三个文件 使用net stop ...
- Hibernate常见错误整理
Hibernate常见错误合集 1.错误:object references an unsaved transient instance - save the transient instance ...
- 【CCS仿真】如何将CCS仿真时memory中的数据以Hex、Integer、 Long 、Float、 Addressable Unit类型保存到PC
2013-12-04 19:07:05 将在CCS中仿真的数据导入电脑上时,可以选择不同的数据类型,以便分析,具体方法如下: 在CCS菜单中,选择File—>Data—>Save,弹出以下 ...
- makefile中的自动化变量 【转】
转自:http://blog.chinaunix.net/uid-28458801-id-3495215.html 自动化变量 模式规则中,规则的目标和依赖文件名代表了一类文件名:规则的命令是对所有这 ...
- android-HttpClient上传信息(包括图片)到服务端
需要下载apache公司下的HttpComponents项目下的HTTPCLIENT ----------地址为http://hc.apache.org/downloads.cgi 主要是用到了htt ...
- [原]poj-1611-The Suspects(水并查集)
题目链接:http://poj.org/problem?id=1611 题意:输入n个人,m个组.初始化0为疑似病例.输入m个小组,每组中只要有一个疑似病例,整组人都是疑似病例.相同的成员可以在不同的 ...