在我的appliaction中我从数据库中获取数据,因为我也提取日期。所以如果用户点击任何特定项目意味着我也将获取该startdate并且我必须将其设置为屏幕中数据选择器中的默认日期。现在提取数据正确,并且带有2个选项“SET”和“CANCEL”的获取数据出现1个对话框,如果我单击设置意味着获取日期不是默认日期,则仅当前日期作为默认值约会。帮助我..提前谢谢。
我的编码:
c = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
System.out.println("After format");
Date pickdefdate=null;
String pickdefdatepar=null;
try {
System.out.println("Inside try="+date);
pickdefdate=sdf.parse(date);
System.out.println("dddddddd="+pickdefdate);
c.setTime(pickdefdate);
System.out.println("After parse");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("B4 setting");
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
showDialog(DATE_DIALOG_ID);
protected Dialog onCreateDialog(int id)
{
switch (id) {
case DATE_DIALOG_ID:
System.out.println("in dia="+mDay);
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
System.out.println("Inside dia");
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
}
};
答案 0 :(得分:0)
你必须扩展onPrepareDialog功能
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case date_picker_dialog_show:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
}}
这将在显示日期选择器日期时更新