zoukankan      html  css  js  c++  java
  • 日历 日期时间选择器

    1.日历

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <CalendarView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:firstDayOfWeek="2"
            android:maxDate="12/31/2016"
            android:minDate="01/01/2016"
            android:id="@+id/cv_1"
            android:background="#999"
            android:visibility="gone">
        </CalendarView>
    
    </LinearLayout>
    View Code

    2.日期选择器

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <DatePicker
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:maxDate="12/31/2023"
            android:minDate="01/01/2000"
            android:calendarViewShown="false"
            android:id="@+id/dp_1"
            android:visibility="gone"
            >
        </DatePicker>
    
    </LinearLayout>
    View Code

    3.时间选择器

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <TimePicker
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tp_1"
            >
        </TimePicker>
    </LinearLayout>
    View Code

    4.代码试行命令

    package com.example.administrator.testapp2;
    
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.CalendarView;
    import android.widget.DatePicker;
    import android.widget.TimePicker;
    import android.widget.Toast;
    
    /**
     * Created by Administrator on 2016/05/07.
     */
    public class TestActivity2 extends AppCompatActivity{
    
        CalendarView cv_1;
        DatePicker dp_1;
        TimePicker tp_1;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test2);
    
            cv_1 = (CalendarView)findViewById(R.id.cv_1);
    
            cv_1.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
                @Override
                public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
    
                    Toast.makeText(TestActivity2.this, "选中的日期是:"+year+"-"+month+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();
                }
            });
    
            dp_1 = (DatePicker)findViewById(R.id.dp_1);
    
            dp_1.init(2015,0,1,new DatePicker.OnDateChangedListener(){
    
                @Override
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    
                    Toast.makeText(TestActivity2.this, "选中的日期是:"+year+"-"+(monthOfYear+1)+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();
                }
            });
    
            tp_1 = (TimePicker)findViewById(R.id.tp_1);
    
            tp_1.setIs24HourView(true);
    
            tp_1.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
                @Override
                public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    
                    Toast.makeText(TestActivity2.this, "选中的时间是:"+hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
                }
            });
        }
    
    
    
    }
    View Code

    5.运行代码目录

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.administrator.testapp2">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".TestActivity2">
                <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
    
        </application>
    
    </manifest>
    View Code
  • 相关阅读:
    Red5/FMS视频直播带宽计算
    基于NPOI开源框架写的ExcelHelper
    Using C# 4.0 and dynamic to parse JSON
    跟我学MVVM模式开发
    supermap使用代码示例(GIS)
    使用OpenXML将Excel内容读取到DataTable中
    ADO 数据类型转换表
    I don't like Regex...
    将Datatable转Excel少于4笔时汉字乱码4/26
    记录宝宝成长脚印3/31
  • 原文地址:https://www.cnblogs.com/bilibiliganbei/p/5478978.html
Copyright © 2011-2022 走看看