Android仿iPhone日期時(shí)間選擇器詳解
本文實(shí)例為大家分享了Android仿iPhone時(shí)間選擇器的具體代碼,供大家參考,具體內(nèi)容如下
先看效果圖
如何使用
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { WheelMain wheelMain; EditText txttime; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txttime = (EditText) findViewById(R.id.txttime); Calendar calendar = Calendar.getInstance(); txttime.setText(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH) + ""); Button btnselecttime = (Button) findViewById(R.id.button1); btnselecttime.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { LayoutInflater inflater = LayoutInflater .from(MainActivity.this); final View timepickerview = inflater.inflate( R.layout.timepicker, null); ScreenInfo screenInfo = new ScreenInfo(MainActivity.this); wheelMain = new WheelMain(timepickerview, true); wheelMain.screenheight = screenInfo.getHeight(); String time = txttime.getText().toString(); Calendar calendar = Calendar.getInstance(); if (JudgeDate.isDate(time, "yyyy-MM-dd")) { try { calendar.setTime(dateFormat.parse(time)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); int h = calendar.getTime().getHours(); int m = calendar.getTime().getMinutes(); wheelMain.initDateTimePicker(year, month, day, h, m); new AlertDialog.Builder(MainActivity.this) .setTitle("選擇時(shí)間") .setView(timepickerview) .setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { txttime.setText(wheelMain.getTime()); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); } }); } }
源碼下載:仿iPhone日期時(shí)間選擇器
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自定義DataTimePicker實(shí)例代碼(日期選擇器)
- Android中的TimePickerView(時(shí)間選擇器)的用法詳解
- Android?studio實(shí)現(xiàn)日期?、時(shí)間選擇器與進(jìn)度條
- Android仿IOS10圓盤時(shí)間選擇器
- Android日期和時(shí)間選擇器實(shí)現(xiàn)代碼
- Android Studio時(shí)間選擇器的創(chuàng)建方法
- Android自定義View仿IOS圓盤時(shí)間選擇器
- Android開發(fā)中實(shí)現(xiàn)IOS風(fēng)格底部選擇器(支持時(shí)間 日期 自定義)
- Android時(shí)間選擇器、日期選擇器實(shí)現(xiàn)代碼
- Android自定義DataTimePicker日期時(shí)間選擇器使用詳解
相關(guān)文章
Android設(shè)備藍(lán)牙連接掃描槍獲取掃描內(nèi)容
這篇文章主要為大家詳細(xì)介紹了Android設(shè)備藍(lán)牙連接掃描槍獲取掃描內(nèi)容,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Android逆向入門之常見Davlik字節(jié)碼解析
Dalvik是Google公司自己設(shè)計(jì)用于Android平臺(tái)的虛擬機(jī)。Dalvik虛擬機(jī)是Google等廠商合作開發(fā)的Android移動(dòng)設(shè)備平臺(tái)的核心組成部分之一,本篇文章我們來(lái)詳細(xì)解釋常見Davlik字節(jié)碼2021-11-11Android數(shù)據(jù)緩存框架內(nèi)置ORM功能使用教程
這篇文章主要為大家介紹了Android數(shù)據(jù)緩存框架內(nèi)置ORM功能使用教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09android BitmapFactory.Options使用方法詳解
這篇文章主要為大家詳細(xì)介紹了android BitmapFactory.Options使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01Android WebView開發(fā)之WebView與Native交互
隨著H5的廣泛使用,Android開發(fā)過(guò)程中免不了會(huì)使用網(wǎng)頁(yè)來(lái)做展示,那么web與native之間的通信就顯得尤其重要了,其實(shí)際上是JavaScript與java之間的通信。本文將為大家詳細(xì)介紹二者是如何實(shí)現(xiàn)交互的,需要的朋友可以參考一下2021-12-12Android開發(fā)實(shí)現(xiàn)切換主題及換膚功能示例
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)切換主題及換膚功能,涉及Android界面布局與樣式動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-03-03Android使用httpPost向服務(wù)器發(fā)送請(qǐng)求的方法
這篇文章主要介紹了Android使用httpPost向服務(wù)器發(fā)送請(qǐng)求的方法,實(shí)例分析了Android針對(duì)HttpPost類的操作技巧,需要的朋友可以參考下2015-12-12