日期修改监听器不管用 求解答
日期修改监听器不管用
private TimePicker timePicker; //生命类型
private DatePicker datePicker1;
private Calendar cal;
private int year,month,day,hour,minute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cal=Calendar.getInstance();//获取日历对象
year=cal.get(Calendar.YEAR);//获取年信息
month=cal.get(Calendar.MONTH)+1;//获取月信息
day=cal.get(Calendar.DAY_OF_MONTH);//获日信息
hour=cal.get(Calendar.HOUR_OF_DAY);//获取分秒信息
minute=cal.get(Calendar.MINUTE);//获取秒信息
setTitle(year+"-"+month+"-"+day+"-"+hour+"-"+minute); //设置为标题
datePicker1= (DatePicker) findViewById(R.id.datePicker);//变量控件绑定
// timePicker= (TimePicker) findViewById(R.id.timePicker1);//变量控件绑定
datePicker1.init(year,cal.get(Calendar.MONTH)+1,day,new DatePicker.OnDateChangedListener() { //datepicker初始化
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// setTitle(year+"年-"+monthOfYear+"月-"+dayOfMonth+"日-"+hour+"小时-"+minute); //设置为标题
// Log.i("Main","用户手指离开屏幕后 通过惯性滑动");//在日志中显示
setTitle("2"); //设置为标题
}
});