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 ...
随机推荐
- 【基础】ASP.net MVC 文件下载的几种方法(欢迎讨论)
在ASP.net MVC 中有几种下载文件的方法 前提:要下载的文件必须是在服务器目录中的,至于不在web项目server目录中的文件下载我不知道,但是还挺想了解的. 第一种:最简单的超链接方法,&l ...
- BZOJ1934:[SHOI2007]善意的投票 & BZOJ2768:[JLOI2010]冠军调查——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=1934 https://www.lydsy.com/JudgeOnline/problem.php? ...
- LOJ 模拟赛
1.LOJ 507 接竹竿 link dp[i]表示前i个的最大分数,所以dp[i]=max(dp[i-1],dp[j-1]+sum[i]-sum[j-1]) (color i ==color j ...
- C++之内部类与外部类(嵌套类)及友元
转载于:http://www.cnblogs.com/qzhforthelife/p/3226885.html 先上代码: class Outer { public: Outer(){m_outerI ...
- HDU 4417 主席树写法
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- C# 枚举的初始化
3.2 枚举类型(Enum types)的默认值 对于枚举类型(Enum types),.NET会自动将字面值0(literal 0)隐式地转换为对应的枚举类型. 3.2.1 有一个0值成员 如果枚举 ...
- 【JSP EL】EL表达式获取当前时间(两种方式)
第一种方式: //先在代码段定义<% long date = new Date().getTime(); request.setAttribute("date", date) ...
- LightOJ 1151 - Snakes and Ladders 高斯消元+概率DP
首先来个期望的论文,讲的非常好,里面也提到了使用线性方程组求解,尤其适用于有向图的期望问题. 算法合集之<浅析竞赛中一类数学期望问题的解决方法> http://www.lightoj.co ...
- uva10766生成树计数(矩阵树定理)
更正了我之前打错的地方,有边的话G[i][j]=-1; WA了好多次,中间要转成long double才行..这个晚点更新. #include<cstdio> #include<cs ...
- bzoj 2079: [Poi2010]Guilds——结论题
Description Zy皇帝面临一个严峻的问题,两个互相抵触的贸易团体,YYD工会和FSR工会,他们在同一时间请求在王国各个城市开办自己的办事处.这里有n个城市,其中有一些以双向马路相连,这两个工 ...