zoukankan      html  css  js  c++  java
  • Android Studio(5)

    1、日期选择器:java部分代码:

    <DatePicker
    android:id="@+id/datapicker"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></DatePicker>

    获取日期java部分代码:

    package com.example.lenovo.android;
    
    import android.app.Activity;
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.RadioGroup;
    import android.widget.Toast;
    
    import java.util.Calendar;
    
    
    public class MainActivity extends Activity {
        int year,month,day;
        DatePicker datePicker;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            datePicker=(DatePicker)findViewById(R.id.datapicker);
            Calendar calendar=Calendar.getInstance();
            year=calendar.get(Calendar.YEAR);
            month=calendar.get(Calendar.MONTH);
            day=calendar.get(Calendar.DAY_OF_MONTH);
            datePicker.init(year,month,day,new DatePicker.OnDateChangedListener(){
                @Override
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    MainActivity.this.year=year;
                    MainActivity.this.month=monthOfYear;
                    MainActivity.this.day=dayOfMonth;
                    show(year,monthOfYear,dayOfMonth);
                }
            });
    
        }
    
        private void show(int year,int month,int day){
            String str=year+"年"+(month+1)+"月"+day+"日";
            Toast.makeText(MainActivity.this,str,Toast.LENGTH_LONG).show();
        }
    } 

     

     2、时间选择器:

    <TimePicker
    android:id="@+id/timepick"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TimePicker>
    获取时间的java代码与上面相似

  • 相关阅读:
    LINQ学习笔记 Join 与 Group join
    JAVA如何解压缩ZIP文档
    Thread.getContextClassLoader() is null
    如何部署 sources and javadoc jars
    Maven部署异常:on project standalone-pom: Cannot deploy artifact from the local repository解决方法
    Git忽略规则及.gitignore规则不生效的解决办法
    Java算法HmacSHA256不可用
    DHCP协议
    【Redis】Redis实现计数器
    【前端】JavaScript原型链与继承
  • 原文地址:https://www.cnblogs.com/tianwenjing123-456/p/12317634.html
Copyright © 2011-2022 走看看