• Android自带的时间控件的使用


    链接:https://www.cnblogs.com/xianfeng-zhang/p/8134269.html

    1,activity代码:

    package com.example.fitness_app.web.teacher;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.TimePicker;
    
    import com.example.fitness_app.R;
    
    public class teacher_addcourseActivity extends AppCompatActivity implements DatePicker.OnDateChangedListener {
        private int Year;
        private  int month;
        private  int day;
        private  int hour;
        private  int min;
    
        private  EditText editText = null;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_teacher_addcourse);
    
            //时间控件
            editText = findViewById(R.id.edittime);
            DatePicker datePicker = findViewById(R.id.coursdaydate);
            datePicker.init(Year,month,day,this);
    //        TimePicker timePicker = new TimePicker();

    TimePicker timePicker = findViewById(R.id.coursdaytime); timePicker.setIs24HourView(true); // editText.setText(Year+"-"+month+"-"+day+" "+hour+":"+min); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { hour = hourOfDay; min = minute; if (minute<10){ hour = hourOfDay; min = minute; Log.i("time","小时"+hour+"分钟"+"0"+min); editText.setText(Year+"-"+month+"-"+day+" "+hour+":"+min); }else { Log.i("time","小时"+hour+"分钟"+min); editText.setText(Year+"-"+month+"-"+day+" "+hour+":"+min); } } }); } @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { month = monthOfYear +1; Year = year; day = dayOfMonth; Log.i("shijian",Year+"年"+month+"月"+day+"日"); editText.setText(Year+"-"+month+"-"+day+" "+hour+":"+min); } }

    2,xml代码

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <DatePicker
                android:id="@+id/coursdaydate"
                android:layout_height="150dp"
                android:layout_width="200dp"
                android:datePickerMode="spinner"
                android:calendarViewShown="false"
                android:startYear="2020"
                android:scrollbarSize="10dp"
                />
            <TimePicker
                android:id="@+id/coursdaytime"
                android:layout_toRightOf="@id/coursdaydate"
                android:layout_width="wrap_content"
                android:layout_height="150dp"
                android:timePickerMode="spinner"></TimePicker>
  • 相关阅读:
    MBG逆向工程报错:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver
    抽取的文件上传类如果注入到容器中??
    使用阿里云OSS,上传图片时报错:java.lang.ClassNotFoundException:org.apache.http.ssl.TrustStrategy
    如何在Eclipse下查看JDK源代码
    mvc架构
    eclipse各版本介绍
    关于mysql MYISAM引擎的锁问题
    忘记mysq rootl密码
    mysql主从
    tomcat启动报错No UserDatabase component found under key UserDatabase
  • 原文地址:https://www.cnblogs.com/wskb/p/12458491.html
Copyright © 2020-2023  润新知