最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android之日期及時(shí)間選擇對(duì)話框用法實(shí)例分析

 更新時(shí)間:2015年09月14日 10:48:16   作者:Ruthless  
這篇文章主要介紹了Android之日期及時(shí)間選擇對(duì)話框用法,以實(shí)例形式較為詳細(xì)的分析了Android創(chuàng)建日期及時(shí)間選擇對(duì)話框的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android之日期及時(shí)間選擇對(duì)話框用法。分享給大家供大家參考。具體如下:

清單文件:

<?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="日期對(duì)話框" 
 android:id="@+id/dateBtn"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />
 <Button android:text="時(shí)間對(duì)話框" 
 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);
  }
 });
 }
 /**
 * 創(chuàng)建日期及時(shí)間選擇對(duì)話框
 */
 @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) // 傳入天數(shù)
  );
  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+"時(shí)"+minute+"分");
   }
  },
  c.get(Calendar.HOUR_OF_DAY),
  c.get(Calendar.MINUTE),
  false
  );
  break;
 }
 return dialog;
 }
}

運(yùn)行結(jié)果:

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

河间市| 岳池县| 武宁县| 白水县| 旅游| 孝感市| 巴彦县| 沁源县| 香河县| 永定县| 木里| 大英县| 昌黎县| 方山县| 加查县| 晋中市| 丰宁| 东乡县| 永川市| 资阳市| 台北县| 建阳市| 慈利县| 龙泉市| 游戏| 昌都县| 沈丘县| 门源| 太仆寺旗| 监利县| 浮梁县| 宁城县| 谢通门县| 福贡县| 仁怀市| 公安县| 库车县| 灵武市| 仁布县| 南召县| 东兴市|