关于DatePickerDialog的问题

public class MainActivity extends Activity {

private TimePicker timePicker;
private DatePicker datePicker;
private Calendar cal;
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.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);
    datePicker=(DatePicker) findViewById(R.id.datePicker);
    timePicker=(TimePicker) findViewById(R.id.timePicker);

    //datePicker初始化
    datePicker.init(year,month,day,new OnDateChangedListener(){

@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}

    });
    timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {

public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
setTitle(hourOfDay+":"+minute);
}
});

    new DatePickerDialog(this, new OnDateChangedListener(){

@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}
}, year, cal.get(Calendar.MONTH), day).show();
}

}

在这串代码中显示: new DatePickerDialog(this, new OnDateChangedListener(){

@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth);
}
}, year, cal.get(Calendar.MONTH), day).show();
}
这一段the constructor DatePickerDialog(MainActivity, new DatePicker.OnDateChangedListener(){}, int, int, int) is undefined

1个回答

说明这个方法不存在啊,我刚看了下,OnDateChangedListener确实没有,只有DatePickerDialog(Context context,
OnDateSetListener callBack,
int year,
int monthOfYear,
int dayOfMonth)
和DatePickerDialog(Context context,
int theme,
OnDateSetListener callBack,
int year,
int monthOfYear,
int dayOfMonth)
两个构造方法。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问