2 u014301482 u014301482 于 2016.04.04 13:51 提问

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

2个回答

CSDNXIAOD
CSDNXIAOD   2016.04.04 14:01

解决DatePickerDialog控件取消按钮有关问题
解决DatePickerDialog和TimePickerDialog控件取消按钮问题
[android] 解决DatePickerDialog和TimePickerDialog控件取消按钮问题
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

u011135662
u011135662   2016.04.05 14:24

说明这个方法不存在啊,我刚看了下,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
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!