android datepicker timepicker简单用法
1.效果图

2. xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/titlebar"
android:layout_height="@dimen/titlebar_height"
android:layout_width="match_parent"
android:background="@color/vi_color"
> <ImageView
android:id="@+id/arrowLeftImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/icon_arrow_left_white"
/>
<TextView
android:id = "@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/White"
android:textSize="@dimen/titlebar_title_text_size"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:text="@string/choose_time"/> </RelativeLayout>
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:layout_gravity="center"
android:contentDescription="设置时间"/>
<!-- <TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="10dp"/> -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:layout_weight="1"> <TextView
android:layout_width="match_parent"
android:id = "@+id/tvTimeShow"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_margin="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id = "@+id/btnCommit"
android:text="@string/ok"
android:background="@drawable/sel_publish_button"/>
</LinearLayout>
</LinearLayout>
3. java 代码
datePicker = (DatePicker) findViewById(R.id.datePicker);
mBtnCommit = (Button) findViewById(R.id.btnCommit);
mTvTimeShow = (TextView) findViewById(R.id.tvTimeShow);
calendar = Calendar.getInstance();
dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
mTvTimeShow.setText("服务起始日期: "+dateFormat.format(calendar.getTime()));
datePicker.init(calendar.get(calendar.YEAR), calendar.get(calendar.MONTH), calendar.get(calendar.DAY_OF_MONTH),
new OnDateChangedListener(){
@Override
public void onDateChanged(DatePicker view, int year,
int month, int day) {
calendar.set(year, month, day);
mTvTimeShow.setText("服务起始日期: "+dateFormat.format(calendar.getTime()));
}
});
/*timePicker.setIs24HourView(false);
timePicker.setOnTimeChangedListener(new OnTimeChangedListener(){
@Override
public void onTimeChanged(TimePicker view, int hour, int minute) {
//calendar.set(year, month, day, hourOfDay, minute);
}
});*/
android datepicker timepicker简单用法的更多相关文章
- Android—— ListView 的简单用法及定制ListView界面
一.ListView的简单用法 2. 训练目标 1) 掌握 ListView 控件的使用 2) 掌握 Adapter 桥梁的作用 实现步骤: 1)首先新建一个项目, 并让ADT 自动帮我们创建好活动. ...
- Android Spinner的简单用法。
今天学到的是spinner,就是下拉列表,这可不是ExpandListView哈. 闲话不解释.这是控件,所以先上布局:就不上线性布局了,基本上可以总结出,控件都得在布局里写,写之前嵌个布局就行. & ...
- Android DatePicker / TimePicker 占空间太大的解决办法
DatePicker 与 TimePicker 控件占用的空间是固定的,没有参数可以更改. 如果修改 length 和 width 属性,只会让控件被切割,显示将不完整.很多人说可以使用 scale ...
- android:ListView 的简单用法
首 先新 建 一个 ListViewTest 项 目, 并 让 ADT 自 动帮 我 们创 建 好 活动 . 然后 修 改 activity_main.xml 中的代码,如下所示: <Linea ...
- android Spinner的简单用法
上代码: spinner = (Spinner) findViewById(R.id.spinner); tv = (TextView) findViewById(R.id.tv); final Ar ...
- 【android】Socket简单用法
Socket通常也称做”套接字“,用于描述IP地址和端口,废话不多说,它就是网络通信过程中端点的抽象表示.值得一提的是,Java在包java.net中提供了两个类Socket和ServerSocket ...
- android#ListView的简单用法
新建项目,并修改项目生产的主文件activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/ap ...
- android的ListAdapter简单用法
ListAdapter是一个整个Activity有且仅有一个ListView控件的Activity 使用步骤:1. 创建MyListViewAdapter(类名可以自定义) extends ListA ...
- android中TimePicker和DatePicker的简单使用
package com.example.demo10; import java.util.Calendar; import android.support.v7.app.ActionBarActivi ...
随机推荐
- 关于Python的 a, b = b, a+b
Python中有一种写法:多个值同时赋给多个变量,如:a, b = b, a+b 1. A写法 a = 0, b = 1 a, b = b, a+b print a, b #结果为:1 1 这种写法, ...
- RESTful Webservice
1,REST和RESTFUL是什么? REST ( REpresentational State Transfer ),State Transfer 为 "状态传输" 或 &quo ...
- 【题解】Atcoder ARC#67 F-Yakiniku Restaurants
觉得我的解法好简单,好优美啊QAQ 首先想想暴力怎么办.暴力的话,我们就枚举左右端点,然后显然每张购物券都取最大的值.这样的复杂度是 \(O(n ^{2} m)\) 的.但是这样明显能够感觉到我们重复 ...
- BZOJ3709 [PA2014]Bohater 【贪心】
题目链接 BZOJ3709 题解 贪心很显然 我们先干掉能回血的怪,当然按照\(d\)升序顺序,因为打得越多血越多,\(d\)大的尽量往后打 然后再干掉会扣血的怪,当然按照\(a\)降序顺序,因为最后 ...
- some of the properties associated with the solution could not be read解决方法
基于TFS管理的解决方案打开时提示:“some of the properties associated with the solution could not be read”,并不影响项目加载,O ...
- POI 10.28
[POI2015]KUR 不考虑构造原串再匹配 考虑开始位置满足什么条件才能匹配. 显然,开始位置确定,后面的字符都确定了. 而且,a,n互质,所以必然能遍历n的剩余系,从不同位置开始,初始的a*s+ ...
- IDEA批量修改变量快捷键
Window: Ctrl+Shift+Alt+J Mac: Ctrl+Option+G
- C/C++中二维数组和指针关系分析
在C/c++中,数组和指针有着密切的关系,有很多地方说数组就是指针式错误的一种说法.这两者是不同的数据结构.其实,在C/c++中没有所谓的二维数组,书面表达就是数组的数组.我猜想是为了表述方便才叫它二 ...
- 洛谷P1667/[10.22 模拟赛] 数列 (思维+模拟)
洛谷P1667 数列 题目描述 给定一个长度是n的数列A,我们称一个数列是完美的,当且仅当对于其任意连续子序列的和都是正的.现在你有一个操作可以改变数列,选择一个区间[X,Y]满足\(A_X +A_{ ...
- Intervals ZOJ - 3953 (区间贪心)
Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that ...