1.日历
2.日期选择器
3.时间选择器
4.代码试行命令
package com.example.administrator.testapp2;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.CalendarView;import android.widget.DatePicker;import android.widget.TimePicker;import android.widget.Toast;/** * Created by Administrator on 2016/05/07. */public class TestActivity2 extends AppCompatActivity{ CalendarView cv_1; DatePicker dp_1; TimePicker tp_1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test2); cv_1 = (CalendarView)findViewById(R.id.cv_1); cv_1.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { @Override public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) { Toast.makeText(TestActivity2.this, "选中的日期是:"+year+"-"+month+"-"+dayOfMonth, Toast.LENGTH_SHORT).show(); } }); dp_1 = (DatePicker)findViewById(R.id.dp_1); dp_1.init(2015,0,1,new DatePicker.OnDateChangedListener(){ @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Toast.makeText(TestActivity2.this, "选中的日期是:"+year+"-"+(monthOfYear+1)+"-"+dayOfMonth, Toast.LENGTH_SHORT).show(); } }); tp_1 = (TimePicker)findViewById(R.id.tp_1); tp_1.setIs24HourView(true); tp_1.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { Toast.makeText(TestActivity2.this, "选中的时间是:"+hourOfDay+":"+minute, Toast.LENGTH_SHORT).show(); } }); }}
5.运行代码目录