zoukankan      html  css  js  c++  java
  • 时间日期视图

    MainActivity

    public class MainActivity extends AppCompatActivity {
    
        CalendarView cv_1;
    
        DatePicker dp_1;
        TimePicker tp_1;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            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(MainActivity.this, "选中的日期是:"+year+"-"+(month+1)+"-"+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(MainActivity.this, "选中的日期是:"+year+"-"+(monthOfYear+1)+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();
    
                }
            });
    
            tp_1=(TimePicker)findViewById(R.id.tp_1);
            tp_1.setIs24HourView(true);//24小时制
            tp_1.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
                @Override
                public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    
                    Toast.makeText(MainActivity.this, "选中的时间是:"+hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
    
                }
            });
        }
    }
    View Code

    actuvity_main

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.lenovo.textapp4.MainActivity"
        android:orientation="vertical">
    
        <CalendarView
            android:layout_width="wrap_content"
            android:layout_height="284dp"
            android:firstDayOfWeek="1"
            android:maxDate="12/31/2016"
            android:minDate="01/01/2016"
            android:id="@+id/cv_1"
            android:visibility="gone">
    
        </CalendarView>
    
        <DatePicker
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:startYear="2010"
            android:endYear="2018"
            android:maxDate="10/1/2017"
            android:minDate="02/01/2010"
            android:id="@+id/dp_1">
    
            <TimePicker
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tp_1">
    
            </TimePicker>
    
        </DatePicker>
    
    </LinearLayout>
    View Code
  • 相关阅读:
    十六、JSONObject与JSONArray使用-不刷新页面做回写显示
    十二、js去掉空格_比较字符长度_中英文判断_页面初始化_简体字与繁字体判断
    十、页面加载时对复选框、下拉列表、单选框默认进行选中及提交请求时判断单选按钮是否选中
    一、什么是Velocity及简单示例
    十八、oracle查看、扩展表空间及linux服务器硬盘容量大小查看
    接口限流算法
    浅析负载均衡的6种算法,Ngnix的5种算法
    今天是JAVA诞生日
    浅谈Spring中JDK动态代理与CGLIB动态代理
    Docker基本命令汇总
  • 原文地址:https://www.cnblogs.com/1ming/p/5480919.html
Copyright © 2011-2022 走看看