请问我的代码为什么无法监听日历改变的事件?
代码如下:
package com.myapp.lee.datetest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
public class MainActivity extends Activity {
private DatePicker dp;
private TimePicker tp;
private Calendar cal;
private TextView tv;
private int year;
private int month;
private int day;
private int hours;
private int min;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.layout);
// tv = (TextView)findViewById(R.id.textView);
cal = Calendar.getInstance();
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH)+1;
day = cal.get(Calendar.DAY_OF_MONTH);
hours = cal.get(Calendar.HOUR_OF_DAY);
min = cal.get(Calendar.MINUTE);
setTitle(year + "/" + month + "/" + day + " " + hours + ":" + min);
dp = (DatePicker)findViewById(R.id.datePicker);
tp = (TimePicker)findViewById(R.id.timePicker);
dp.init(year, cal.get(Calendar.MONTH), day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Log.i("tag", "Done");
setTitle(year + "/" + monthOfYear + "/" + dayOfMonth);
}
});
}
}