android时钟显示
来源:互联网 发布:微博桌面2015网络异常 编辑:程序博客网 时间:2024/05/10 00:37
在android应用中时常用的时间的显示,下面是一个简单的时钟显示设计。
页面显示:
布局设计:
main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><AnalogClock android:layout_width="fill_parent"android:layout_height="wrap_content" /><DigitalClock android:layout_width="wrap_content"android:layout_height="wrap_content" android:textSize="18dp"></DigitalClock><Button android:id="@+id/button1" android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="显示TimePickerDialog"></Button><Button android:id="@+id/button2" android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="显示DatePickerDialog"></Button></LinearLayout>
代码显示:
main.java:
import java.util.Calendar;import android.app.Activity;import android.app.DatePickerDialog;import android.app.TimePickerDialog;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.DatePicker;import android.widget.TimePicker;import android.widget.Toast;public class Main extends Activity implements OnClickListener {/** Called when the activity is first created. */private Button button1, button2;private int hourOfDay, minute;private int year, monthOfYear, dayOfMonth;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);button1 = (Button) this.findViewById(R.id.button1);button2 = (Button) this.findViewById(R.id.button2);button1.setOnClickListener(this);button2.setOnClickListener(this);// 获得当前的时间,获得小时和分钟Calendar calendar = Calendar.getInstance();hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);minute = calendar.get(Calendar.MINUTE);// 获得当前的秒year = calendar.get(Calendar.YEAR);monthOfYear = calendar.get(Calendar.MONTH);dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);}public void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.button1://TimePickerDialog timePickerDialog = new TimePickerDialog(Main.this,new MyTimePickerDialog(), hourOfDay, minute, true);timePickerDialog.show();// 显示对话框break;case R.id.button2:DatePickerDialog datePickerDialog = new DatePickerDialog(Main.this,new MyDatePickerDialog(), year, monthOfYear, dayOfMonth);datePickerDialog.show();// 显示对话框break;}}public class MyDatePickerDialog implementsDatePickerDialog.OnDateSetListener {public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {// TODO Auto-generated method stubToast.makeText(Main.this,"year:" + year + "monthOfYear:" + monthOfYear+ "dayOfMonth:" + dayOfMonth, 1).show();}}public class MyTimePickerDialog implementsTimePickerDialog.OnTimeSetListener {public void onTimeSet(TimePicker view, int hourOfDay, int minute) {// TODO Auto-generated method stubToast.makeText(Main.this,"hourOfDay:" + hourOfDay + "minute:" + minute, 1).show();}}}
- android时钟显示
- android 获取时钟信息并显示
- android自定义view(实现时钟显示)
- 时钟显示
- 显示时钟
- 显示时钟
- 一个实时显示系统时钟的android应用
- Android时钟
- android 时钟
- 在状态栏显示时钟
- javascript显示时钟
- 鼠标光环-显示时钟
- SWT 界面时钟显示
- javascript显示一个时钟
- 时钟计时显示
- 网页时钟显示^_^
- js实现时钟显示
- OpenGL时钟显示
- 微软面试100题系列-第1题
- tar命令的C参数
- System.DateTime.Now.ToString()日常用法
- WinDbug 配置
- linux下dd命令详解
- android时钟显示
- java对字符串操作大全
- 数据库方面的面试题
- 基于android的旅游攻略应用(含源码)
- grep的使用
- 解决开启Gzip压缩后 某些浏览器访问不正常
- 【TCP连接】三次握手和四次挥手
- php5.3.x连接sql server 2005 (php5.3连接mssql)
- Set Matrix Zeroes