Android之日期及时间选择对话框用法实例分析

Android之日期及时间选择对话框用法实例分析,第1张

概述本文实例讲述了Android之日期及时间选择对话框用法。分享给大家供大家参考。具体如下:

本文实例讲述了AndroID之日期及时间选择对话框用法。分享给大家供大家参考。具体如下:

清单文件:

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.ljq.dialog" androID:versionCode="1" androID:versionname="1.0"> <application androID:icon="@drawable/icon" androID:label="@string/app_name"> <activity androID:name=".AlertDialog"   androID:label="@string/app_name">  <intent-filter>  <action androID:name="androID.intent.action.MAIN" />  <category androID:name="androID.intent.category.LAUNCHER" />  </intent-filter> </activity> </application> <uses-sdk androID:minSdkVersion="7" /> <uses-permission androID:name="androID.permission.WRITE_CALENDAR" /></manifest> 

main.xml布局文件:

<?xml version="1.0" enCoding="utf-8"?><linearLayout androID:ID="@+ID/linearLayout01" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical" xmlns:androID="http://schemas.androID.com/apk/res/androID"> <EditText androID:ID="@+ID/et"  androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"  androID:editable="false" androID:cursorVisible="false" /> <button androID:text="日期对话框"  androID:ID="@+ID/dateBtn" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /> <button androID:text="时间对话框"  androID:ID="@+ID/timeBtn" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /> <DigitalClock  androID:text="@+ID/digitalClock" androID:textSize="20dip"  androID:gravity="center" androID:ID="@+ID/DigitalClock01"  androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /> <AnalogClock  androID:ID="@+ID/analogClock" androID:gravity="center"  androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" /></linearLayout>

AlertActivity类:

package com.ljq.dialog;import java.util.Calendar;import androID.app.Activity;import androID.app.DatePickerDialog;import androID.app.Dialog;import androID.app.TimePickerDialog;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.DatePicker;import androID.Widget.EditText;import androID.Widget.TimePicker;public class AlertDialog extends Activity { private button dateBtn = null; private button timeBtn = null; private EditText et=null; private final static int DATE_DIALOG = 0; private final static int TIME_DIALOG = 1; private Calendar c = null; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); et=(EditText)findVIEwByID(R.ID.et); dateBtn = (button) findVIEwByID(R.ID.dateBtn); timeBtn = (button) findVIEwByID(R.ID.timeBtn); dateBtn.setonClickListener(new VIEw.OnClickListener(){  public voID onClick(VIEw v) {  showDialog(DATE_DIALOG);  } }); timeBtn.setonClickListener(new VIEw.OnClickListener(){  public voID onClick(VIEw v) {  showDialog(TIME_DIALOG);  } }); } /** * 创建日期及时间选择对话框 */ @OverrIDe protected Dialog onCreateDialog(int ID) { Dialog dialog = null; switch (ID) { case DATE_DIALOG:  c = Calendar.getInstance();  dialog = new DatePickerDialog(  this,new DatePickerDialog.OnDateSetListener() {   public voID onDateSet(DatePicker dp,int year,int month,int dayOfMonth) {   et.setText("您选择了:" + year + "年" + (month+1) + "月" + dayOfMonth + "日");   }  },c.get(Calendar.YEAR),// 传入年份  c.get(Calendar.MONTH),// 传入月份  c.get(Calendar.DAY_OF_MONTH) // 传入天数  );  break; case TIME_DIALOG:  c=Calendar.getInstance();  dialog=new TimePickerDialog(  this,new TimePickerDialog.OnTimeSetListener(){   public voID onTimeSet(TimePicker vIEw,int hourOfDay,int minute) {   et.setText("您选择了:"+hourOfDay+"时"+minute+"分");   }  },c.get(Calendar.HOUR_OF_DAY),c.get(Calendar.MINUTE),false  );  break; } return dialog; }}

运行结果:

希望本文所述对大家的AndroID程序设计有所帮助。

总结

以上是内存溢出为你收集整理的Android之日期及时间选择对话框用法实例分析全部内容,希望文章能够帮你解决Android之日期及时间选择对话框用法实例分析所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1141359.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存