像datepicker一样,也有timepicker。

同样有timepickerdialog

所用到的方法还是一样,监听时间选择器的变化。

 package com.example.alimjan.hello_world;

 import java.util.Calendar;

 /**
* Created by alimjan on 7/15/2017.
*/ import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TimePicker;
import android.widget.TextView; public class class_5_1_2d extends AppCompatActivity implements
OnClickListener, OnTimeSetListener { private TextView tv_time; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.code_5_1_2);
tv_time = (TextView) findViewById(R.id.tv_time);
findViewById(R.id.btn_time).setOnClickListener(this);
} @Override
public void onClick(View v) {
if (v.getId() == R.id.btn_time) {
Calendar calendar = Calendar.getInstance();
TimePickerDialog dialog = new TimePickerDialog(this, this,
calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true);
dialog.show();
}
} @Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String desc = String.format("您选择的时间是%d时%d分", hourOfDay, minute);
tv_time.setText(desc);
} public static void startHome(Context mContext) {
Intent intent = new Intent(mContext, class_5_1_2d.class);
mContext.startActivity(intent);
} }
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" > <Button
android:id="@+id/btn_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="请选择时间"
android:textColor="@color/black"
android:textSize="20sp" /> <TextView
android:id="@+id/tv_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="17sp" /> </LinearLayout>

Android 开发笔记___时间选择器---timePicker的更多相关文章

  1. Android 开发笔记___DatePicker__日期选择器

    虽然EditText提供了inputTtype="date",但用户往往不太喜欢自己输入时间. Android为这个提供了DatePicker,但有很多缺点,不是弹窗模式,而是直接 ...

  2. Android 开发笔记___实战项目:购物车

    购物车的应用很广泛,电商app基本上都有它的身影.由于它用到了多种存储方式,通过项目对数据的存储有更高层次的了解. 1.设计思路 首先看看购物车的外观.第一次进入时里面是空的,去购物页面加入购物车以后 ...

  3. Android 开发笔记___基本适配器的使用__BaseAdapter

    之前用到过ArryAdapter适用于纯文本的列表数据,SimpleAdapter适用于带图标的列表数据,但在实际应用中常常有更复杂的列表,比如同一项中存在多个控件,这时候用前面的两个会比较复杂,而且 ...

  4. Android 开发笔记___存储方式__共享参数__sharedprefences

    Android 的数据存储方式有四种,这次是[共享参数__sharedprefences] 听起来挺别扭的,平时看到的app里面,当用户删除了一些软件以后下次安装,发现原来的设置还在,这种情况就是把一 ...

  5. Android 开发笔记___登陆app

    package com.example.alimjan.hello_world; /** * Created by alimjan on 7/4/2017. */ import android.con ...

  6. Android 开发笔记___复选框__checkbox

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  7. Android 开发笔记___初级控件之实战__计算器

    功能简单,实现并不难,对于初学者可以总和了解初级控件的基本使用. 用到的知识点如下: 线性布局 LinearLayout:整体界面是从上往下的,因此需要垂直方向的linearlayout:下面每行四个 ...

  8. Android 开发笔记___图像按钮__imageButton

    IMAGEBUTTON 其实派生自image view,而不是派生自button.,image view拥有的属性和方法,image button 统统拥有,只是imagebutton有个默认的按钮外 ...

  9. Android 开发笔记___滚动视图__scroll view

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

随机推荐

  1. VCL组件之TLabel、TStaticText和TLabeledEdit

    TLabel.TStaticText.TLabeledEdit类的继承关系如下:

  2. 增大hadoop client内存

    export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS" 问题场景:sqoop import时报OOM

  3. mysql 时间函数 时间转换函数

    时间函数 Now 获取当前时间 current_timestamp 获取当前时间 localtimestamp 时间转换 UNIX_TIMESTAMP    "2009-09-15 00:0 ...

  4. 玩转 sublime3 第二弹 ES6环境

    安装node: node作为JS的运行环境必须安装 文件下载:https://nodejs.org/dist/v6.11.4/node-v6.11.4-x64.msi 备注:可以去官网 https:/ ...

  5. qplot函数用法(转载)

    http://blog.csdn.net/u014801157/article/details/24372499 写的很全面 放在这里记录下

  6. java数据库编程之初始Mysql

    2.3:命令行连接mySql 2.3.1:检查是否启动服务 步骤:计算机-----管理------服务和应用程序-------服务---搜索mysql右键启动服务 2.3.2:命令行方式连接数据库 步 ...

  7. java 虚拟机与并发处理几个问题简要(二)

    六.两个重要的概念性问题: 1.同步:要保持数据的一致性,就需要一种保证并发进程正确执行顺序的机制.这种机制就是 进程同步(Process Synchronization). 竞争资源的多个进程按着特 ...

  8. 使用svn与maven管理的项目导入Eclipse,但是与本地svn客户端关联不上?

    因为这个问题,导致我的项目导了删,删了导.现在终于弄明白了. 首先,需求场景是:    1.使用svn进行版本控制;    2.使用maven进行项目管理.    3.使用Tortoise svn将项 ...

  9. cocos2dx - 节点管理

    接上一节内容:cocos2dx - v2.3.3编辑器骨骼动画 本节主要Cocos2dx中节点的管理及应用 一般用法 用过Cocos2dx应该都有用过addChild,removeChild方法.或者 ...

  10. 【转载】jQuery全屏滚动插件fullPage.js

    文章转载自dowebok http://www.dowebok.com/ 原文链接:http://www.dowebok.com/77.html 简介 如今我们经常能见到全屏网站,尤其是国外网站.这些 ...