关于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

查看全部
u014301482
angieChoo
2016/04/04 05:51
  • android
  • 点赞
  • 收藏
  • 回答
    私信

1个回复