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 ...
随机推荐
- BZOJ2301:[HAOI2011]Problem b——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2301 https://www.luogu.org/problemnew/show/P2522 对于给 ...
- bzoj2165: 大楼(倍增floyd)
题目大意:一个有向图,n(<=100)个点求一条长度>=m(<=10^18)的路径最少经过几条边. 一开始以为是矩乘,蓝鹅当时还没开始写,所以好像给CYC安利错了嘿嘿嘿QWQ 第一眼 ...
- python 多线程实现
多线程和多进程是什么自行google补脑 对于python 多线程的理解,我花了很长时间,搜索的大部份文章都不够通俗易懂.所以,这里力图用简单的例子,让你对多线程有个初步的认识. 单线程 在好些年前的 ...
- Codeforces Round #337 (Div. 2)B
B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- New Year and Domino 二维前缀和
C. New Year and Domino time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- C++虚基类的初始化
#include<iostream> using namespace std; class Base{ public: Base(int sa) { a=sa; cout<<& ...
- C#学习之自定义数组及其排序
在C#中对数组的定义比较灵活.这里着重说一下自定义数组和Array类的排序. 在Array类中通过属性Length就可以获取整个数组中数据的数量,可以通过foreach迭代数组. 使用Rank属性可以 ...
- POJ1015 DP
Jury Compromise Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28927 Accepted: 7676 ...
- 不可不知的robots.txt文件
robots.txt基本介绍 robots.txt是一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的内容. 当一个搜索机器人(有的叫搜索 ...
- php 生成压缩文件
$fileList = array( "site_upload/form_file_clause_extend/20180224/1519456901_1481718257.jpg" ...