标签:
DatePicker 是android下的日期选择器,类似的有TimePicker等。DatePicker 常用定义如下:
<DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:calendarViewShown="false" />
其中calendarViewShown是控制样式是否显示日历,通常选择为false。
DatePicker 典型代码如下:
Calendar calendar =Calendar.getInstance(); int year =calendar.get(Calendar.YEAR); int monthOfYear =calendar.get(Calendar.MONTH); int dayOfMonth =calendar.get(Calendar.DAY_OF_MONTH); datepicker.init(year, monthOfYear, dayOfMonth, new OnDateChangedListener(){ public void onDateChanged(DatePicker view, int year, int month, int day) { String tmp = year + "/" + (month+1) + "/" + day;//这里的month返回的是索引,从0开始 Toast toast = new Toast(MainActivity.this); toast = Toast.makeText(getApplicationContext(), tmp, Toast.LENGTH_SHORT); toast.show(); } });
标签:
原文地址:http://www.cnblogs.com/Fredric-2013/p/4245404.html