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 ...
随机推荐
- P2580 于是他错误的点名开始了
题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...
- [BZOJ5463] [APIO2018] 铁人两项
题目链接 LOJ. BZOJ. Solution 先建圆方树. 我们考虑暴力,枚举一个点对,我们枚举的点都是圆点,然后统计中间那个点可以取的位置的数量,加起来就是答案. 那么怎么统计呢,我们对于每个点 ...
- Codeforces Round #469 (Div. 2) E. Data Center Maintenance
tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...
- BZOJ4200 & 洛谷2304 & UOJ132:[NOI2015]小园丁与老司机——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4200 https://www.luogu.org/problemnew/show/P2304 ht ...
- BZOJ4698 & 洛谷2463:[SDOI2008]Sandy的卡片——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4698 https://www.luogu.org/problemnew/show/P2463#sub ...
- BZOJ4873 [Shoi2017]寿司餐厅 【最大权闭合子图】
题目链接 BZOJ4873 题解 题意很鬼畜,就可以考虑网络流[雾] 然后就会发现这是一个裸的最大权闭合子图 就是注意要离散化一下代号 #include<algorithm> #inclu ...
- 解决jsp两种提交方式乱码 的方法
解决中文乱码 ---post提交方式 需要在处理页面添加request.setCharacterEncoding("utf-8"); 制定请求的编码,调用一下request.ge ...
- Unresolved import *** (models) error on Eclipse
Eclipse version: Oxygen.2 Release (4.7.2) Python version: 3.6 问题:系统提示:from django.db import models 语 ...
- BZOJ1898: [Zjoi2005]Swamp 沼泽鳄鱼(矩阵乘法)
1898: [Zjoi2005]Swamp 沼泽鳄鱼 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1898 Description 潘塔 ...
- Saddle Point ZOJ - 3955 题意题
Chiaki has an n × m matrix A. Rows are numbered from 1 to n from top to bottom and columns are numbe ...