`
rayln
  • 浏览: 417881 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Datepicker窗口控件

 
阅读更多
由于使用弹出式窗口的日期控件, 不需要在main.xml中定义标签
只需要写java代码即可

package com.cn;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class DatepickerActivity extends Activity {
	private TextView mDateDisplay;
    private Button mPickDate;
    private int mYear;
    private int mMonth;
    private int mDay;

    static final int DATE_DIALOG_ID = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
     // capture our View elements
        mDateDisplay = (TextView) findViewById(R.id.textView1);
        mPickDate = (Button) findViewById(R.id.button1);

        // add a click listener to the button
        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });

        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        // display the current date (this method is below)
        updateDisplay();
    }
 // updates the date in the TextView
    private void updateDisplay() {
        mDateDisplay.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mMonth + 1).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" "));
    }
 // the callback received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, 
                              int monthOfYear, int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            updateDisplay();
        }
    };
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this,
                        mDateSetListener,
                        mYear, mMonth, mDay);
        }
        return null;
    }
        
}

分享到:
评论

相关推荐

    ASP.NET基础控件-教程

     打开新的窗口并传送参数  为按钮添加对话框  删除表格选定记录  删除表格记录警告  关于日期格式  表格超连接列传递参数  清空Cookie  获取错误信息并到指定页面  自定义异常处理  javascript小技巧  ...

    OA办公软件myoffice 有数据库

    运行环境:IE8以下 (因为IE8不支持低版本的My97DatePicker日历控件) 需要安装Ajax主要控件 运行平台:Windows2000或者以上 开发周期:2009.10.7——2009.11.7 本人完成模块:人事管理 日程管理的bug调试和修改 ...

    EXTJS实用开发指南_个人整理笔记.pdf

    1. 基本控件:Box、Button、ColorPalette、Component、Container、CycleButton、DataView、DatePicker、Editor、EditorGridPanel、Grid、PagingToolbar、Panel、ProgressBar、SplitButton、TabPanel、TreePanel、...

    MUI教程[整理].pdf

    MUI框架提供了多种控件,如accordion(折叠面板)、button(按钮)、actionsheet(操作表)、badge(数字角标)、datepicker(时间选择器)、dialog对话框、input(表单)、list(列表/图文列表)、progressbar...

    最后提交按钮的时候可以验证1987-08-18这样格式的验证

    时间验证源码:2里写的是js验证:单击按钮时进行验证的方法; 共3个比较好看的时间控件;...2里是用比较多的控件 My97DatePicker,最后提交按钮的时候可以验证1987-08-18这样格式的验证 在bin里有几个.dll 时间控件

    ExtAspNet_v2.3.2_dll

    -一个典型应用,在Window控件中打开新页面,如果传递的参数不正确,则首先提示参数不对然后关闭此弹出窗口。 -ExtAspNet.Alert.Show("参数错误!", String.Empty, ExtAspNet.ActiveWindow.GetCloseReference());...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -为TextBox,TextArea,DatePicker,NumberBox,TriggerBox等控件增加AutoPostBack属性(feedback:dk3214)。 +为表单字段增加RequiredMessage,MaxLengthMessage,MinLengthMessage属性,用于指定验证失败时提示信息。 ...

    asp.net开发常用整理集合

     打开新的窗口并传送参数  为按钮添加对话框  删除表格选定记录  删除表格记录警告  关于日期格式  表格超连接列传递参数  清空Cookie  获取错误信息并到指定页面  自定义异常处理  javascript...

    yii2-date-time-picker-widget:用于Yii2的Bootstrap DateTimePicker窗口小部件

    用于Yii2的Bootstrap DateTimePicker窗口小部件 呈现。安装安装此扩展的首选方法是通过 。 无论运行composer require 2amigos/yii2-date-time-picker-widget: ~ 1.0 或添加 " 2amigos/yii2-date-time-picker-widget ...

    Android基础知识详解

    DatePicker、TimePicker 66 AnalogClock、DigitalClock 68 单选框、复选框、开关状态按钮 69 单项选择(RadioGroup、RadioButton) 69 复选框(CheckBox) 71 开关状态按钮(ToggleButton) 73 下拉列表框Spinner 74 ...

    Excel百宝箱9.0无限制破解版.rar

    【截取窗口对象】:将选定的窗口或者对象转换成图片文件,可截Excel界面和其它任意界面 【截取矩形对象】:将选定的矩形区域转换成图片文件 【截取任意区域】:将选定任意区域转换成图片文件 【删除空单元格】:...

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox...

    Google Android SDK开发范例大全的目录

    第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——CheckBox...

    Google+Android+SDK开发范例大全

    ——具选择功能的对话框 3.21 Android变脸——主题(Theme)实现 第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    第4章 史上超豪华的手机控件 4.1 EditText与TextView共舞——setOnKeyListener事件 4.2 设计具有背景图的按钮——ImageButton的焦点及事件处理 4.3 给耶诞老人的信息——Toast对象的使用 4.4 我同意条款——...

Global site tag (gtag.js) - Google Analytics