像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. 在JavaScript中使用json.js:访问JSON编码的某个值

    演示: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...

  2. Object.defineProperty()方法的用法详解

    Object.defineProperty()函数是给对象设置属性的. Object.defineProperty(object, propertyname, descriptor); 一共有三个参数 ...

  3. AES加解密算法Qt实现

    [声明] (1) 本文源码 在一位未署名网友源码基础上,利用Qt编程,实现了AES加解密算法,并添加了文件加解密功能.在此表示感谢!该源码仅供学习交流,请勿用于商业目的. (2) 图片及描述 除图1外 ...

  4. Linux系统管理命令(1)accton的使用

    安装: apt install acct accton accton命令是Linux系统进程管理命令之一,它的作用是打开进程统计,如果不带任何参数,即关闭进程统计.         具体用法为:acc ...

  5. 机器学习之numpy库中常用的函数介绍(一)

    1. mat() mat()与array的区别: mat是矩阵,数据必须是2维的,是array的子集,包含array的所有特性,所做的运算都是针对矩阵来进行的. array是数组,数据可以是多维的,所 ...

  6. Suneast & Daxia (规律)

    Suneast & Daxia Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u ...

  7. An Introduction to Variational Methods (5.2)

    我们现在已经得到了关于潜在变量Z的优化分布的表达形式: ‍ 其中: ‍ 所以现在我们可以得到Z的期望: ‍ 另外对于Z还值得一提的是,我们从其优化分布的表达式中可以看出,各个Z的组成部分之间还是相互耦 ...

  8. Monit : 开源监控工具介绍

    · Monit 简介 Monit是一个轻量级(500KB)跨平台的用来监控Unix/linux系统的开源工具.部署简单,并且不依赖任何第三方程序.插件或者库. Monit可以监控服务器进程.文件.文件 ...

  9. windows下PHP中Fatal error Call to undefined function curl_init()的解决方法

    参考官方解决方法:http://nz.php.net/manual/en/curl.installation.php 1.php安装目录下的ext文件夹下面是否有php_curl.dll文件,然后右键 ...

  10. XML读取信息并显示

    这个类命名叫Message.cs namespace Common { public class Message { /// <summary> /// 信息编号 /// </sum ...