編輯:關於Android編程
Android 日期和時間的使用
日期和時間的使用;
1:彈出框TimePickerDialog,DatePickerDialog
2:組件TimePicker,DatePicker
TimePickerDialog的使用:通過點擊button顯示圖一,然後用戶可以設置時間
DatePickerDialog的使用只需要將TimePickerDialog修改成DatePickerDialog, TimePickerDialog.OnTimeSetListener 分別修改成DatePickerDialog,OnDateSetListener既可
public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener { //用戶創建彈出時間框的方法 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current time as the default values for the picker final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity())); } public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Do something with the time chosen by the user } }
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pick_time" android:onClick="showTimePickerDialog" />
public void showTimePickerDialog(View v) { DialogFragment newFragment = new TimePickerFragment(); newFragment.show(getSupportFragmentManager(), "timePicker"); }
DatePickerDialog的代碼:
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { //用戶創建日期對話框的時間方法 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day); return dialog; } @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
寫在最前(這是對上一篇博文的問題做的更新【android利用zbar二維碼掃描】) 前天早上登陸CSDN時候一條消息:一網友提出了兩點疑惑 &
1、概述Android提供了幾種動畫類型:View Animation 、Drawable Animation 、Property Animation 。View An
有不少朋友為自己的手機鎖屏後設置了開鎖密碼,但如果忘記了手機解鎖圖案設置,不管是因為太過復雜,還是別的什麼原因,用上手機才是最重要的,下載吧小編就來分享一個
介紹今天上班的時候有個哥們問我怎麼去實現一個按鈕式的進度條,先來看看他需要實現的效果圖。和普通的圓形進度條類似,只是中間的地方有兩個狀態表示,未開始,暫停狀態。而且他說圓