欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)之DatePickerDialog、TimePickerDialog時間日期對話框用法示例

 更新時間:2019年03月15日 11:31:24   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之DatePickerDialog、TimePickerDialog時間日期對話框用法,結(jié)合實例形式分析了Android使用DatePickerDialog、TimePickerDialog顯示日期時間相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)之DatePickerDialog、TimePickerDialog時間日期對話框用法。分享給大家供大家參考,具體如下:

用法:

一、創(chuàng)建兩個 DatePickerDialog、TimePickerDialog 實例調(diào)用 show() 方法即可將他們顯示出來

二、為 DatePickerDialog、TimePickerDialog 實例分別綁定監(jiān)聽器,通過監(jiān)聽獲得用戶設(shè)置

效果:

DatePickerDialog

TimePickerDialog

下面是具體的實現(xiàn)方法:

public class MainActivity extends Activity {
 private Button buttonDate;
 private Button buttonTime;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  buttonDate = (Button) findViewById(R.id.dataBn);
  buttonTime = (Button) findViewById(R.id.timeBn);
  iniClick();//Binding the listeners for you program
 }
 public void iniClick(){
  //set listener for your Date button
  buttonDate.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Calendar calendar = Calendar.getInstance();
    //create a datePickerDialog and then shoe it on your screen
    new DatePickerDialog(MainActivity.this,//binding the listener for your DatePickerDialog
      new DatePickerDialog.OnDateSetListener() {
       @Override
       public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
        Toast.makeText(MainActivity.this,"Year:" + year + " Month:" + month + " Day:" + dayOfMonth,Toast.LENGTH_SHORT).show();
       }
      }
      , calendar.get(Calendar.YEAR)
      , calendar.get(Calendar.MONTH)
      , calendar.get(Calendar.DAY_OF_MONTH)).show();
   }
  });
  //set listener for your Time button
  buttonTime.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Calendar calendar = Calendar.getInstance();
    //create a datePickerDialog and then shoe it on your screen
    new TimePickerDialog(MainActivity.this,
      new TimePickerDialog.OnTimeSetListener() {
       @Override
       public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        Toast.makeText(MainActivity.this,"Hour:" + hourOfDay + " Minute:" + minute ,Toast.LENGTH_SHORT).show();
       }
      }
      , calendar.get(Calendar.HOUR_OF_DAY)
      , calendar.get(Calendar.MINUTE)
      , true).show();
   }
  });
 }
}

這里是布局文件:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/idtatabHost"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal"
 android:layout_weight="1">
 <Button
  android:id="@+id/dataBn"
  android:text="點我一下 挑日期"
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="wrap_content" />
 <Button
  android:id="@+id/timeBn"
  android:text="點我一下 挑時間 。。。"
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="wrap_content" />
</LinearLayout>

PS:這里再為大家推薦幾款關(guān)于日期與時間計算的在線工具供大家參考使用:

在線日期/天數(shù)計算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi

在線萬年歷日歷:
http://tools.jb51.net/bianmin/wannianli

在線陰歷/陽歷轉(zhuǎn)換工具:
http://tools.jb51.net/bianmin/yinli2yangli

Unix時間戳(timestamp)轉(zhuǎn)換工具:
http://tools.jb51.net/code/unixtime

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android日期與時間操作技巧總結(jié)》、《Android開發(fā)入門與進階教程》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

最新評論