Android 仿iPhone的日期時間選取器

來源:互聯網
上載者:User

標籤:

可選只選擇日期,也可以同時選擇時間
只選擇日期的情況

 

同時選擇日期和時間的情況

 

 

關鍵代碼:

 

findViewById(R.id.selectDateButton).setOnClickListener(new OnClickListener() {public void onClick(View v) {View timepickerview=LayoutInflater.from(getContext()).inflate(R.layout.timepicker, null);ScreenInfo screenInfo = new ScreenInfo(getContext());wheelMain = new WheelMain(timepickerview,hasTime);wheelMain.screenheight = screenInfo.getHeight();String time = itemValue.getText().toString();Calendar calendar = Calendar.getInstance();if(JudgeDate.isDate(time, formatStr)){try {calendar.setTime(dateFormat.parse(time));} catch (ParseException e) {e.printStackTrace();}}int year = calendar.get(Calendar.YEAR);int month = calendar.get(Calendar.MONTH);int day = calendar.get(Calendar.DAY_OF_MONTH);int hour = calendar.get(Calendar.HOUR_OF_DAY);int min = calendar.get(Calendar.MINUTE);if(hasTime)wheelMain.initDateTimePicker(year,month,day,hour,min);elsewheelMain.initDateTimePicker(year,month,day);new AlertDialog.Builder(context).setTitle("選擇時間").setView(timepickerview).setPositiveButton("確定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {itemValue.setText(wheelMain.getTime());}}).setNegativeButton("取消", null).show();}});WheelMain wheelMain = new WheelMain(timepickerview,hasTime);if(hasTime)wheelMain.initDateTimePicker(year,month,day,hour,min);elsewheelMain.initDateTimePicker(year,month,day);

 

代碼:這裡

 

Android 仿iPhone的日期時間選取器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.