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圓盤(pán)時(shí)間選擇器
- Android日期和時(shí)間選擇器實(shí)現(xiàn)代碼
- Android Studio時(shí)間選擇器的創(chuàng)建方法
- Android自定義View仿IOS圓盤(pán)時(shí)間選擇器
- Android開(kāi)發(fā)中實(shí)現(xiàn)IOS風(fēng)格底部選擇器(支持時(shí)間 日期 自定義)
- Android時(shí)間選擇器、日期選擇器實(shí)現(xiàn)代碼
- Android自定義DataTimePicker日期時(shí)間選擇器使用詳解
相關(guān)文章
android實(shí)現(xiàn)手機(jī)與單片機(jī)藍(lán)牙模塊通信
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)手機(jī)與單片機(jī)藍(lán)牙模塊通信的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android Binder進(jìn)程間通信工具AIDL使用示例深入分析
Binder作為Android 眾多的IPC通訊手段之一,在Framework的數(shù)據(jù)傳輸中起到極為關(guān)鍵的作用。Binder機(jī)制可謂是Android 知識(shí)體系里的重中之重,作為偏底層的基礎(chǔ)組件,平時(shí)我們很少關(guān)注它,而它卻是無(wú)處不在,也是Android 面試易考察的點(diǎn)之一2022-11-11
Android邊框裁切的正確姿勢(shì)實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Android邊框裁切的正確姿勢(shì)實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
android獲取屏幕高度和寬度的實(shí)現(xiàn)方法
這篇文章主要介紹了android獲取屏幕高度和寬度的實(shí)現(xiàn)方法,較為詳細(xì)的分析了Android獲取屏幕高度和寬度的原理與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01
Android消息機(jī)制Handler用法總結(jié)
這篇文章介紹了Android消息機(jī)制Handler用法總結(jié),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-11-11
Android實(shí)現(xiàn)手勢(shì)滑動(dòng)多點(diǎn)觸摸縮放平移圖片效果(二)
這篇文章主要介紹了Android實(shí)現(xiàn)手勢(shì)滑動(dòng)多點(diǎn)觸摸縮放平移圖片效果,實(shí)現(xiàn)圖片支持多點(diǎn)觸控,自由的進(jìn)行縮放、平移的注意事項(xiàng),感興趣的小伙伴們可以參考一下2016-02-02

