日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

日历 日期时间选择器

發(fā)布時(shí)間:2024/9/5 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 日历 日期时间选择器 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.日歷

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:orientation="vertical" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <CalendarView 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:firstDayOfWeek="2" 10 android:maxDate="12/31/2016" 11 android:minDate="01/01/2016" 12 android:id="@+id/cv_1" 13 android:background="#999" 14 android:visibility="gone"> 15 </CalendarView> 16 17 </LinearLayout>

2.日期選擇器

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:orientation="vertical" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <DatePicker 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:maxDate="12/31/2023" 10 android:minDate="01/01/2000" 11 android:calendarViewShown="false" 12 android:id="@+id/dp_1" 13 android:visibility="gone" 14 > 15 </DatePicker> 16 17 </LinearLayout>

3.時(shí)間選擇器

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:orientation="vertical" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <TimePicker 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:id="@+id/tp_1" 10 > 11 </TimePicker> 12 </LinearLayout>

4.代碼試行命令

1 package com.example.administrator.testapp2; 2 3 import android.os.Bundle; 4 import android.support.v7.app.AppCompatActivity; 5 import android.widget.CalendarView; 6 import android.widget.DatePicker; 7 import android.widget.TimePicker; 8 import android.widget.Toast; 9 10 /** 11 * Created by Administrator on 2016/05/07. 12 */ 13 public class TestActivity2 extends AppCompatActivity{ 14 15 CalendarView cv_1; 16 DatePicker dp_1; 17 TimePicker tp_1; 18 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_test2); 23 24 cv_1 = (CalendarView)findViewById(R.id.cv_1); 25 26 cv_1.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { 27 @Override 28 public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) { 29 30 Toast.makeText(TestActivity2.this, "選中的日期是:"+year+"-"+month+"-"+dayOfMonth, Toast.LENGTH_SHORT).show(); 31 } 32 }); 33 34 dp_1 = (DatePicker)findViewById(R.id.dp_1); 35 36 dp_1.init(2015,0,1,new DatePicker.OnDateChangedListener(){ 37 38 @Override 39 public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 40 41 Toast.makeText(TestActivity2.this, "選中的日期是:"+year+"-"+(monthOfYear+1)+"-"+dayOfMonth, Toast.LENGTH_SHORT).show(); 42 } 43 }); 44 45 tp_1 = (TimePicker)findViewById(R.id.tp_1); 46 47 tp_1.setIs24HourView(true); 48 49 tp_1.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { 50 @Override 51 public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { 52 53 Toast.makeText(TestActivity2.this, "選中的時(shí)間是:"+hourOfDay+":"+minute, Toast.LENGTH_SHORT).show(); 54 } 55 }); 56 } 57 58 59 60 }

5.運(yùn)行代碼目錄

1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.administrator.testapp2"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme"> 11 <activity android:name=".TestActivity2"> 12 <intent-filter> 13 <action android:name="android.intent.action.MAIN" /> 14 <category android:name="android.intent.category.LAUNCHER" /> 15 </intent-filter> 16 </activity> 17 18 </application> 19 20 </manifest>

?

轉(zhuǎn)載于:https://www.cnblogs.com/TENOKAWA/p/5471190.html

總結(jié)

以上是生活随笔為你收集整理的日历 日期时间选择器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。