2个Dialog对话框,一个可显示当前年月日,另外一个可以显示当前时间,并在点“确定”的时候,可进行回调操作。
//这里是显示月月日对话框 public void click1(View v) { Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int monthOfYear = c.get(Calendar.MONTH); int dayOfMonth = c.get(Calendar.DAY_OF_MONTH); new DatePickerDialog(this, new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // 点击确定后想干什么在这里实现 Toast.makeText(getApplicationContext(), year + "-" + monthOfYear + "-" + dayOfMonth, 0).show(); } }, year, monthOfYear, dayOfMonth).show(); } //这里显示的是时间对话框 public void click2(View v) { Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); new TimePickerDialog(this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // 点击确定后想干什么在这里实现 } }, hour, minute, true).show(); }
效果图:
本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1740889
原文地址:http://liuxudong1001.blog.51cto.com/10877072/1740889