DatePickerDialog

DatePickerDialog

"date ten tyear

DatePickerDialog:android日期選擇對話框。
android api 對其描述如下:
This class is a widget for selecting a date. The date can be selected by a year, month, and day spinners or aCalendarView. The set of spinners and the calendar view are automatically synchronized. The client can customize whether only the spinners, or only the calendar view, or both to be displayed. Also the minimal and maximal date from which dates to be selected can be customized.
案例如下:

publicclassDatePickerDialogActivityextendsActivity {
EditTextcurrentTime;
EditTextsetTime;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
String time =newSimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(newDate());
currentTime.setText(time);
currentTime.setEnabled(false);
setTime.setOnClickListener(newOnClickListener() {
@Override
publicvoidonClick(View v) {
dialog().show();
}
});
}
privatevoidinit() {
currentTime = (EditText)this.findViewById(R.id.current_time);
setTime= (EditText)this.findViewById(R.id.set_time);
}
publicDatePickerDialog dialog(){
DatePickerDialog datePickerDialog =
newDatePickerDialog(DatePickerDialogActivity.this,
newOnDateSetListener() {
@Override
publicvoidonDateSet(DatePicker view,intyear,intmonthOfYear,
intdayOfMonth) {
Stringdate = year+"-"+monthOfYear+"-"+dayOfMonth;
setTime.setText(date);
}
},2013, 6, 6);
returndatePickerDialog;
}
}

相關詞條

熱門詞條

聯絡我們