我這裏有代碼的選項菜單上安卓的DatePicker和DatePicker的對話框
Dialog dialog = new Dialog(ScheduleActivity.this);
dialog.setTitle("Add Event");
dialog.setContentView(R.layout.add_even_on);
Button datePicker = (Button) dialog.findViewById(R.id.datePicker);
final DialogFragment dateFrag = new MyDatePicker();
datePicker.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dateFrag.show(getSupportFragmentManager(), "datePicker");
}
});
dialog.show();
時,說「添加事件」選項菜單上點擊時,會出現一個對話框,有一個按鈕,顯示DatePickerDialog並在它旁邊是一個TextView,它反映了DatePickerDialog中選擇的日期,這裏是我從Androids Developer獲得的關於如何使用DatePickerDialog的類。
class MyDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {
int pYear;
int pDay;
int pMonth;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
pYear = year;
pDay = day;
pMonth = month;
}
}
所以我的問題是,我如何獲得milleseconds值當我點擊「設置」就這又自動關閉它的DatePickerDialog,並返回到我的對話,其中包含打開DatePickerDialog和按鈕一個TextView反映選擇了DatePickerDialog watever日期...我不會顯示一個我選擇了DatePickerDialog內...
這裏是我的意思的圖片,
因此,當我上挑點擊日期按鈕DatePickerDialog框出現,如下圖所示
,當我點擊設置,我想那DatePickerDialog
這是最接近我做什麼,我艱難的做了一些修改,我並沒有完全使用所有的方法,但它足夠接近礦井.. tnx – lemoncodes 2012-08-10 06:31:15
showDialog(DATE_DIALOG_ID);已棄用。使用對話框片段代替http://stackoverflow.com/questions/11220820/the-method-showdialogint-from-the-type-activity-is-deprecated-in-android http://stackoverflow.com/questions/12710092/how - 使用片段管理員對sobstitute-depri-showdialog – 2013-05-03 15:36:40