码迷,mamicode.com
首页 > 移动开发 > 详细

Android DatePicker和TimePicker

时间:2015-09-22 18:44:30      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

监测日期改变的监听器:
     OnDateChangedListener和OnTimeChangedListener()
          当用户改变Datepicker里的年、月、日时,将触发OnDateChangedListener的OnTimeChange事件。
当用户更改TimePicker里的时、分、时,将触发OnTimeChangedListener监听器的OnTimeChanged事件
     OnDateSetListener和OnTimeSetListener()
          当用户更改了DatePickerDialog里的年、月、日时,将触发OnDateSetListener监听器的onDateSet()事件
          当用户更改了TimePickerDialog里的时,分时,将触发OnTimeSetListener监听器的onTimeSet()事件。
public class MainActivity extends Activity {
 
 
        private TimePicker timePicker;
        private DatePicker datePicker ;
        private Calendar calendar ;
        private int year ;
        private int month ;
        private int day ;
        private int hour;
        private int minute;
       
        @Override
        protected void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
              setContentView(R.layout. activity_main);
               calendar=Calendar. getInstance();
               year= calendar.get( calendar. YEAR);
               month= calendar.get( calendar. MONTH);
               day= calendar.get( calendar. DAY_OF_MONTH);
              setTitle( year+ month+ day);
               datePicker=(DatePicker) findViewById(R.id.datePicker1);
               timePicker=(TimePicker) findViewById(R.id.timePicker1);
               //datepicker 初始化
               datePicker.init(year , month , day , new OnDateChangedListener() {
                     
                      @Override
                      public void onDateChanged(DatePicker view, int year, int monthOfYear,
                                   int dayOfMonth) {
                           
                           setTitle(year+ ""+monthOfYear+1+"" +dayOfMonth);
                     }
              });
       }

Android DatePicker和TimePicker

标签:

原文地址:http://www.cnblogs.com/stareblankly/p/4829271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!