Android日期选择器实现年月日三级联动

最近项目里面用到了一个日期选择器,实现现在主流的WheelView滑动选择,整理了下,做了个Demo.废话不多说,直接上代码.

主布局:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.user.mydate.MainActivity"> 

  <TextView
    android:id="@+id/selectDate"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:gravity="center"
    android:onClick="selectDate"
    android:clickable="true"
    android:text="日期选择" />
</RelativeLayout> 

MainActivity:

package com.example.user.mydate; 

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast; 

import com.example.user.mydate.view.ChangeDatePopwindow; 

public class MainActivity extends Activity { 

  private TextView selectDate;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    selectDate= (TextView) findViewById(R.id.selectDate);
  } 

  public void selectDate(View v){
    if (v.getId()==R.id.selectDate){
      selectDate();
    } 

  } 

  private String[] selectDate() {
    final String[] str = new String[10];
    ChangeDatePopwindow mChangeBirthDialog = new ChangeDatePopwindow(
        this);
    mChangeBirthDialog.setDate("2016", "1", "1");
    mChangeBirthDialog.showAtLocation(selectDate, Gravity.BOTTOM, 0, 0);
    mChangeBirthDialog.setBirthdayListener(new ChangeDatePopwindow.OnBirthListener() { 

      @Override
      public void onClick(String year, String month, String day) {
        // TODO Auto-generated method stub
        Toast.makeText(MainActivity.this,year + "-" + month + "-" + day,Toast.LENGTH_LONG).show();
        StringBuilder sb = new StringBuilder();
        sb.append(year.substring(0, year.length() - 1)).append("-").append(month.substring(0, day.length() - 1)).append("-").append(day);
        str[0] = year + "-" + month + "-" + day;
        str[1] = sb.toString();
        selectDate.setText(year + "-" + month + "-" + day); 

      }
    });
    return str;
  } 

}

主要的类:

package com.example.user.mydate.view; 

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView; 

import com.example.user.mydate.R;
import com.example.user.mydate.view.wheelview.OnWheelChangedListener;
import com.example.user.mydate.view.wheelview.OnWheelScrollListener;
import com.example.user.mydate.view.wheelview.WheelView;
import com.example.user.mydate.view.wheelview.adapter.AbstractWheelTextAdapter1; 

import java.util.ArrayList;
import java.util.Calendar; 

/**
 * Author: Chen.yuan
 * Email:  hubeiqiyuan2010@163.com
 * Date:  2016/7/28 17:37
 * Description:日期选择window
 */
public class ChangeDatePopwindow extends PopupWindow implements View.OnClickListener { 

  private Context context;
  private WheelView wvYear;
  private WheelView wvMonth;
  private WheelView wvDay; 

  private TextView btnSure;
  private TextView btnCancel; 

  private ArrayList<String> arry_years = new ArrayList<String>();
  private ArrayList<String> arry_months = new ArrayList<String>();
  private ArrayList<String> arry_days = new ArrayList<String>();
  private CalendarTextAdapter mYearAdapter;
  private CalendarTextAdapter mMonthAdapter;
  private CalendarTextAdapter mDaydapter; 

  private String month;
  private String day; 

  private String currentYear = getYear();
  private String currentMonth = getMonth();
  private String currentDay = getDay(); 

  private int maxTextSize = 24;
  private int minTextSize = 14; 

  private boolean issetdata = false; 

  private String selectYear;
  private String selectMonth;
  private String selectDay; 

  private OnBirthListener onBirthListener; 

  public ChangeDatePopwindow(final Context context) {
    super(context);
    this.context = context;
    View view=View.inflate(context, R.layout.dialog_myinfo_changebirth,null);
    wvYear = (WheelView) view.findViewById(R.id.wv_birth_year);
    wvMonth = (WheelView) view.findViewById(R.id.wv_birth_month);
    wvDay = (WheelView) view.findViewById(R.id.wv_birth_day);
    btnSure = (TextView) view.findViewById(R.id.btn_myinfo_sure);
    btnCancel = (TextView) view.findViewById(R.id.btn_myinfo_cancel); 

    //设置SelectPicPopupWindow的View
    this.setContentView(view);
    //设置SelectPicPopupWindow弹出窗体的宽
    this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    //设置SelectPicPopupWindow弹出窗体的高
    this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
    //设置SelectPicPopupWindow弹出窗体可点击
    this.setFocusable(true);
    //设置SelectPicPopupWindow弹出窗体动画效果
//   this.setAnimationStyle(R.style.AnimBottom);
    //实例化一个ColorDrawable颜色为半透明
    ColorDrawable dw = new ColorDrawable(0xb0000000);
    //设置SelectPicPopupWindow弹出窗体的背景
    this.setBackgroundDrawable(dw); 

    btnSure.setOnClickListener(this);
    btnCancel.setOnClickListener(this); 

    if (!issetdata) {
      initData();
    }
    initYears();
    mYearAdapter = new CalendarTextAdapter(context, arry_years, setYear(currentYear), maxTextSize, minTextSize);
    wvYear.setVisibleItems(5);
    wvYear.setViewAdapter(mYearAdapter);
    wvYear.setCurrentItem(setYear(currentYear)); 

    initMonths(Integer.parseInt(month));
    mMonthAdapter = new CalendarTextAdapter(context, arry_months, setMonth(currentMonth), maxTextSize, minTextSize);
    wvMonth.setVisibleItems(5);
    wvMonth.setViewAdapter(mMonthAdapter);
    wvMonth.setCurrentItem(setMonth(currentMonth)); 

    initDays(Integer.parseInt(day));
    mDaydapter = new CalendarTextAdapter(context, arry_days, Integer.parseInt(currentDay) - 1, maxTextSize, minTextSize);
    wvDay.setVisibleItems(5);
    wvDay.setViewAdapter(mDaydapter);
    wvDay.setCurrentItem(Integer.parseInt(currentDay) - 1); 

    wvYear.addChangingListener(new OnWheelChangedListener() { 

      @Override
      public void onChanged(WheelView wheel, int oldValue, int newValue) {
        // TODO Auto-generated method stub
        String currentText = (String) mYearAdapter.getItemText(wheel.getCurrentItem());
        selectYear = currentText;
        setTextviewSize(currentText, mYearAdapter);
        currentYear = currentText.substring(0, currentText.length()-1).toString();
        Log.d("currentYear==",currentYear);
        setYear(currentYear);
        initMonths(Integer.parseInt(month));
        mMonthAdapter = new CalendarTextAdapter(context, arry_months, 0, maxTextSize, minTextSize);
        wvMonth.setVisibleItems(5);
        wvMonth.setViewAdapter(mMonthAdapter);
        wvMonth.setCurrentItem(0); 

        calDays(currentYear, month);
      }
    }); 

    wvYear.addScrollingListener(new OnWheelScrollListener() { 

      @Override
      public void onScrollingStarted(WheelView wheel) {
        // TODO Auto-generated method stub 

      } 

      @Override
      public void onScrollingFinished(WheelView wheel) {
        // TODO Auto-generated method stub
        String currentText = (String) mYearAdapter.getItemText(wheel.getCurrentItem());
        setTextviewSize(currentText, mYearAdapter);
      }
    }); 

    wvMonth.addChangingListener(new OnWheelChangedListener() { 

      @Override
      public void onChanged(WheelView wheel, int oldValue, int newValue) {
        // TODO Auto-generated method stub
        String currentText = (String) mMonthAdapter.getItemText(wheel.getCurrentItem());
        selectMonth = currentText;
        setTextviewSize(currentText, mMonthAdapter);
        setMonth(currentText.substring(0, 1));
        initDays(Integer.parseInt(day));
        mDaydapter = new CalendarTextAdapter(context, arry_days, 0, maxTextSize, minTextSize);
        wvDay.setVisibleItems(5);
        wvDay.setViewAdapter(mDaydapter);
        wvDay.setCurrentItem(0); 

        calDays(currentYear, month);
      }
    }); 

    wvMonth.addScrollingListener(new OnWheelScrollListener() { 

      @Override
      public void onScrollingStarted(WheelView wheel) {
        // TODO Auto-generated method stub 

      } 

      @Override
      public void onScrollingFinished(WheelView wheel) {
        // TODO Auto-generated method stub
        String currentText = (String) mMonthAdapter.getItemText(wheel.getCurrentItem());
        setTextviewSize(currentText, mMonthAdapter);
      }
    }); 

    wvDay.addChangingListener(new OnWheelChangedListener() { 

      @Override
      public void onChanged(WheelView wheel, int oldValue, int newValue) {
        // TODO Auto-generated method stub
        String currentText = (String) mDaydapter.getItemText(wheel.getCurrentItem());
        setTextviewSize(currentText, mDaydapter);
        selectDay = currentText;
      }
    }); 

    wvDay.addScrollingListener(new OnWheelScrollListener() { 

      @Override
      public void onScrollingStarted(WheelView wheel) {
        // TODO Auto-generated method stub 

      } 

      @Override
      public void onScrollingFinished(WheelView wheel) {
        // TODO Auto-generated method stub
        String currentText = (String) mDaydapter.getItemText(wheel.getCurrentItem());
        setTextviewSize(currentText, mDaydapter);
      }
    });
  } 

  public void initYears() {
    for (int i = Integer.parseInt(getYear()); i > 1950; i--) {
      arry_years.add(i + "年");
    }
  } 

  public void initMonths(int months) {
    arry_months.clear();
    for (int i = 1; i <= months; i++) {
      arry_months.add(i + "月");
    }
  } 

  public void initDays(int days) {
    arry_days.clear();
    for (int i = 1; i <= days; i++) {
      arry_days.add(i + "日");
    }
  } 

  private class CalendarTextAdapter extends AbstractWheelTextAdapter1 {
    ArrayList<String> list; 

    protected CalendarTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize, int minsize) {
      super(context, R.layout.item_birth_year, NO_RESOURCE, currentItem, maxsize, minsize);
      this.list = list;
      setItemTextResource(R.id.tempValue);
    } 

    @Override
    public View getItem(int index, View cachedView, ViewGroup parent) {
      View view = super.getItem(index, cachedView, parent);
      return view;
    } 

    @Override
    public int getItemsCount() {
      return list.size();
    } 

    @Override
    protected CharSequence getItemText(int index) {
      return list.get(index) + "";
    }
  } 

  public void setBirthdayListener(OnBirthListener onBirthListener) {
    this.onBirthListener = onBirthListener;
  } 

  @Override
  public void onClick(View v) { 

    if (v == btnSure) {
      if (onBirthListener != null) {
        onBirthListener.onClick(selectYear, selectMonth, selectDay);
        Log.d("cy",""+selectYear+""+selectMonth+""+selectDay);
      }
    } else if (v == btnSure) { 

    } else {
      dismiss();
    }
    dismiss(); 

  } 

  public interface OnBirthListener {
    public void onClick(String year, String month, String day);
  } 

  /**
   * 设置字体大小
   *
   * @param curriteItemText
   * @param adapter
   */
  public void setTextviewSize(String curriteItemText, CalendarTextAdapter adapter) {
    ArrayList<View> arrayList = adapter.getTestViews();
    int size = arrayList.size();
    String currentText;
    for (int i = 0; i < size; i++) {
      TextView textvew = (TextView) arrayList.get(i);
      currentText = textvew.getText().toString();
      if (curriteItemText.equals(currentText)) {
        textvew.setTextSize(maxTextSize);
      } else {
        textvew.setTextSize(minTextSize);
      }
    }
  } 

  public String getYear() {
    Calendar c = Calendar.getInstance();
    return c.get(Calendar.YEAR)+"";
  } 

  public String getMonth() {
    Calendar c = Calendar.getInstance();
    return c.get(Calendar.MONTH) + 1+"";
  } 

  public String getDay() {
    Calendar c = Calendar.getInstance();
    return c.get(Calendar.DATE)+"";
  } 

  public void initData() {
    setDate(getYear(), getMonth(), getDay());
    this.currentDay = 1+"";
    this.currentMonth = 1+"";
  } 

  /**
   * 设置年月日
   *
   * @param year
   * @param month
   * @param day
   */
  public void setDate(String year, String month, String day) {
    selectYear = year + "年";
    selectMonth = month + "月";
    selectDay = day + "日";
    issetdata = true;
    this.currentYear = year;
    this.currentMonth = month;
    this.currentDay = day;
    if (year == getYear()) {
      this.month = getMonth();
    } else {
      this.month = 12+"";
    }
    calDays(year, month);
  } 

  /**
   * 设置年份
   *
   * @param year
   */
  public int setYear(String year) {
    int yearIndex = 0;
    if (!year.equals(getYear())) {
      this.month = 12+"";
    } else {
      this.month = getMonth();
    }
    for (int i = Integer.parseInt(getYear()); i > 1950; i--) {
      if (i == Integer.parseInt(year)) {
        return yearIndex;
      }
      yearIndex++;
    }
    return yearIndex;
  } 

  /**
   * 设置月份
   *
   * @param month
   * @param month
   * @return
   */
  public int setMonth(String month) {
    int monthIndex = 0;
    calDays(currentYear, month);
    for (int i = 1; i < Integer.parseInt(this.month); i++) {
      if (Integer.parseInt(month) == i) {
        return monthIndex;
      } else {
        monthIndex++;
      }
    }
    return monthIndex;
  } 

  /**
   * 计算每月多少天
   *
   * @param month
   * @param year
   */
  public void calDays(String year, String month) {
    boolean leayyear = false;
    if (Integer.parseInt(year) % 4 == 0 && Integer.parseInt(year) % 100 != 0) {
      leayyear = true;
    } else {
      leayyear = false;
    }
    for (int i = 1; i <= 12; i++) {
      switch (Integer.parseInt(month)) {
      case 1:
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
        this.day = 31+"";
        break;
      case 2:
        if (leayyear) {
          this.day = 29+"";
        } else {
          this.day = 28+"";
        }
        break;
      case 4:
      case 6:
      case 9:
      case 11:
        this.day = 30+"";
        break;
      }
    }
    if (year.equals( getYear()) && month .equals( getMonth())) {
      this.day = getDay();
    }
  }
}

底部弹出框布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ly_myinfo_changeaddress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_transparent"
android:gravity="bottom"
android:orientation="vertical" > 

<LinearLayout
  android:id="@+id/ly_myinfo_changeaddress_child"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:background="@color/white"
  android:orientation="vertical" > 

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="44dp"
    > 

    <TextView
      android:id="@+id/btn_myinfo_cancel"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:paddingLeft="12dp"
      android:text="取消"
      android:gravity="center"
      android:layout_alignParentLeft="true"
      android:layout_marginRight="15dip"
      android:textColor="@color/color_e84515"
      android:textSize="13sp" /> 

    <TextView
      android:id="@+id/btn_myinfo_sure"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      android:gravity="center"
      android:text="完成"
      android:textColor="@color/color_e84515"
      android:paddingRight="12dp"
      android:textSize="12sp" /> 

  </RelativeLayout>
  <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="@color/color_d8d8d8"
    />
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="160dip"
    android:orientation="horizontal"
    android:gravity="center_vertical">
    <com.example.user.mydate.view.wheelview.WheelView
      android:id="@+id/wv_birth_year"
      android:layout_width="0dip"
      android:layout_weight="1"
      android:layout_height="match_parent"
      android:layout_gravity="center_vertical"
      />
    <com.example.user.mydate.view.wheelview.WheelView
      android:id="@+id/wv_birth_month"
      android:layout_width="0dip"
      android:layout_weight="1"
      android:layout_height="match_parent"
      android:layout_gravity="center_vertical"
      /> 

    <com.example.user.mydate.view.wheelview.WheelView
      android:id="@+id/wv_birth_day"
      android:layout_width="0dip"
      android:layout_weight="1"
      android:layout_height="match_parent"
      android:layout_gravity="center_vertical"
      />
  </LinearLayout> 

</LinearLayout> 

</LinearLayout>

运行效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

您可能感兴趣的文章:

  • Android中使用开源框架Citypickerview实现省市区三级联动选择
  • Android自定义WheelView地区选择三级联动
  • Android省市区三级联动控件使用方法实例讲解
  • android-wheel控件实现三级联动效果
  • Android使用android-wheel实现省市县三级联动
  • Android实现三级联动下拉框 下拉列表spinner的实例代码
  • 最好用的Android省市区三级联动选择效果
(0)

相关推荐

  • Android使用android-wheel实现省市县三级联动

    今天没事跟群里面侃大山,有个哥们说道Android Wheel这个控件,以为是Andriod内置的控件,google一把,发现是个github上的一个控件. 下载地址:https://code.google.com/p/android-wheel/    发现很适合做省市县三级联动就做了一个. 先看下效果图: 1.首先导入github上的wheel项目 2.新建个项目,然后选择记得右键->Properties->Android中将wheel添加为lib: 上面两个步骤是导入所有开源项目的过程了

  • 最好用的Android省市区三级联动选择效果

    Android省市区选择三级联动效果,一个不大不小的功能,就算你做过,但是没有相关的代码直接写,也要花掉你至少半天时间. 下面我写出我的实现过程(思路绝对清晰). 先上效果图 一.准备数据 我是用的本地的json数据(走网络的话太慢,每次都要请求),放在asserts中.格式如下: [{ "name": "河北省", "city": [ { "name": "石家庄市", "area":

  • Android中使用开源框架Citypickerview实现省市区三级联动选择

    1.概述 记得之前做商城项目,需要在地址选择中实现省市区三级联动,方便用户快速的填写地址,当时使用的是一个叫做android-wheel 的开源控件,当时感觉非常好用,唯一麻烦的是需要自己整理并解析省市区的xml文件,思路很简单,但是代码量相对大了些.偶然期间发现了另外一个开源组件,也就是今天要介绍的citypickerview. github地址:crazyandcoder/citypicker 2. 实现效果 下面给大家演示下实现效果: 3.   实现方法 (1)添加依赖 dependenc

  • Android实现三级联动下拉框 下拉列表spinner的实例代码

    主要实现办法:动态加载各级下拉值的适配器 在监听本级下拉框,当本级下拉框的选中值改变时,随之修改下级的适配器的绑定值              XML布局: 复制代码 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_w

  • Android省市区三级联动控件使用方法实例讲解

    最近有需求需要实现省市区三级联动,但是发现之前的实现不够灵活,自己做了一些优化.为了方便以后使用,抽离出来放在了github上WheelView.同时把其核心库放在了JCenter中了,可以直接引用.也可以参考项目中的Demo进行引用 下面介绍一下如何使用 如果用的是AndroidStudio那么直接在build.gradle文件中添加依赖: dependencies { compile 'chuck.WheelItemView:library:1.0.1' } 成功引入库之后,可以在需要弹出省

  • Android自定义WheelView地区选择三级联动

    本文实例为大家分享了WheelView地区选择三级联动的具体代码,供大家参考,具体内容如下 1. 效果 最近需要做一个地区选择的功能,但是在网上和github上找了很久都没找到满意的,然后朋友推荐了一个给我,我花了点时间把代码大致看懂并改成我想要的,并写上我的理解.效果如图: 2. 注意 a. 首先我们要明白,网上这写三级联动的demo,不管是把数据库文件放在raw还是assets中,我们都要进行复制,将这个文件复制到app目录下,即 /data/data/"+context.getPackag

  • android-wheel控件实现三级联动效果

    本文实例为大家分享了android wheel省市县三级联动效果,供大家参考,具体内容如下 在github上面有一个叫做 Android-wheel 的开源控件, 代码地址:https://github.com/maarek/android-wheel 源码下载地址:http://xiazai.jb51.net/201610/yuanma/AndroidCascadeMaster(jb51.net).rar 主界面布局 activity_main.xml <LinearLayout xmlns:

  • Android日期选择器实现年月日三级联动

    最近项目里面用到了一个日期选择器,实现现在主流的WheelView滑动选择,整理了下,做了个Demo.废话不多说,直接上代码. 主布局:activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&quo

  • 利用select实现年月日三级联动的日期选择效果【推荐】

    前面的话 关于select控件,可能年月日三级联动的日期选择效果是最常见的应用了.本文是选择框脚本的实践,下面将对日期选择效果进行详细介绍 规划 默认情况下,年.月.日分别由3个select控件组成,id分别为sel1,sel2,sel3.它们且所包含的option[0]的值,分别为'年'.'月'.'日' 年份范围为1900-2100,月份范围为1-12,天的范围为1-31 年份范围.月份范围是不变的.而天的范围根据实际日期的计算来改变其范围值 id为result的span元素储存最终选择的日期

  • 基于JavaScript实现年月日三级联动

    本文实例为大家分享了JavaScript实现年月日三级联动的具体代码,供大家参考,具体内容如下 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>年月日三级联动</title> </head> <body onload="initYear(),initMonth()&qu

  • Android 日期选择器实例代码

    废话不多说了,直接给大家贴代码了,具体代码如下所示: //出生年月设置 private void birthSetting() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, 1); new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() { @Override public void onDat

  • android实现下拉菜单三级联动

    android中的下拉菜单联动应用非常普遍,android中的下拉菜单用Spinner就能实现,以下列子通过简单的代码实现三级菜单联动. 一 样式文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_p

  • Android实现院系专业三级联动

    Android实现院系专业三级联动,供大家参考,具体内容如下 设计一个注册页面 注册项:用户名.密码.学号.性别.爱好.学院.系.专业. 具体要求如下 1.学号只能输入数字 2.密码框要隐藏,8-24位之间 3.性别用单选框,默认选中男 4.爱好用多选框,默认选中第二个选项 5.院.系和专业选择使用下拉列表框(先院,后系.最后专业.要求院系专业之间是联动的,例如:选中了计算机学院,第二个系列表框里只能有该学院的几个系,选中了某一个系,第三个专业列表框里只能有该系对应的专业) 6.点击注册按钮,在

  • Android日期选择器对话框DatePickerDialog使用详解

    调用Android原生日期选择器对话框就是DatePickerDialog,具体内容如下 在Android4.4系统上效果如图: 在Android5.0以上效果如图: 1.Activity的onCreate方法中获取当时的年,月,日 Calendar ca = Calendar.getInstance(); mYear = ca.get(Calendar.YEAR); mMonth = ca.get(Calendar.MONTH); mDay = ca.get(Calendar.DAY_OF_M

  • javascript实现日期三级联动下拉框选择菜单

    由于工作中涉及到生日编辑资料编辑,年月日用上面网址案例:bug提示: 编辑生日栏的[年]或者[月],之前保存的具体的[日]就不显示啦,产品说不管编辑哪个数据,其他数据不变: 然后自己改了一下代码: <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width,initial-scale=1,minimu

  • Android时间选择器、日期选择器实现代码

    本文为大家分享了两款选择器,一款可以针对时间进行选择.一款可以针对日期进行选择,供大家参考,具体内容如下 一.时间选择器 1.1.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.and

随机推荐