Android开发之 DatePicker & TimePicker
Android开发之 DatePicker & TimePicker
落叶挽歌 发表于9个月前
Android开发之 DatePicker & TimePicker
  • 发表于 9个月前
  • 阅读 3
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

`

    timePicker = (TimePicker)findViewById(R.id.timePicker1);

    datePicker=(DatePicker)findViewById(R.id.datePicker1);
   
    
    calendar = Calendar.getInstance();//获取一个日历对象
    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH)+1;
    day = calendar.get(Calendar.DAY_OF_MONTH);
    hour = calendar.get(Calendar.HOUR_OF_DAY);
    minute = calendar.get(Calendar.MINUTE);
  
    //初始化日期选择组件,并在初始化时设计OnDateChangedListener()监听事件
    datePicker.init(year, month, day, new OnDateChangedListener() {
		
		[@Override](https://my.oschina.net/u/1162528)
		public void onDateChanged(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			// TODO Auto-generated method stub
			  setTitle(year+"年"+monthOfYear+"月"+dayOfMonth+1+"日");
		}
	});
    //设置时间监听OnTimeChangedListener()事件
    timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
		
		[@Override](https://my.oschina.net/u/1162528)
		public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
			// TODO Auto-generated method stub
			setTitle(hourOfDay+":"+minute+"");
		}
	});
    
    //创建DatePickerDialog对象
    //        new DatePickerDialog(this, new OnDateSetListener() {
    //			
    //			[@Override](https://my.oschina.net/u/1162528)
    //			public void onDateSet(DatePicker view, int year, int monthOfYear,
    //					int dayOfMonth) {
    //				// TODO Auto-generated method stub
    //				 setTitle(year+"年"+monthOfYear+"月"+dayOfMonth+1+"日");
    //			}
    //		}, year, calendar.get(Calendar.MONTH), day).show();
    
  //创建TimePickerDialog对象
    new TimePickerDialog(this, new OnTimeSetListener() {
		
		[@Override](https://my.oschina.net/u/1162528)
		public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
			// TODO Auto-generated method stub
			setTitle(hourOfDay+":"+minute+"");
		}
	}, hour, minute, true).show();
    
   
   
}`
共有 人打赏支持
粉丝 0
博文 22
码字总数 5705
×
落叶挽歌
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: