Android仿iPhone日期時間選擇器詳解
更新時間:2017年11月24日 14:02:15 作者:DylanAndroid
這篇文章主要為大家詳細介紹了Android仿iPhone日期時間選擇器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Android仿iPhone時間選擇器的具體代碼,供大家參考,具體內(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("選擇時間")
.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日期時間選擇器
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Android自定義DataTimePicker實例代碼(日期選擇器)
- Android中的TimePickerView(時間選擇器)的用法詳解
- Android?studio實現(xiàn)日期?、時間選擇器與進度條
- Android仿IOS10圓盤時間選擇器
- Android日期和時間選擇器實現(xiàn)代碼
- Android Studio時間選擇器的創(chuàng)建方法
- Android自定義View仿IOS圓盤時間選擇器
- Android開發(fā)中實現(xiàn)IOS風格底部選擇器(支持時間 日期 自定義)
- Android時間選擇器、日期選擇器實現(xiàn)代碼
- Android自定義DataTimePicker日期時間選擇器使用詳解
相關(guān)文章
Android Binder進程間通信工具AIDL使用示例深入分析
Binder作為Android 眾多的IPC通訊手段之一,在Framework的數(shù)據(jù)傳輸中起到極為關(guān)鍵的作用。Binder機制可謂是Android 知識體系里的重中之重,作為偏底層的基礎組件,平時我們很少關(guān)注它,而它卻是無處不在,也是Android 面試易考察的點之一2022-11-11
Android實現(xiàn)手勢滑動多點觸摸縮放平移圖片效果(二)
這篇文章主要介紹了Android實現(xiàn)手勢滑動多點觸摸縮放平移圖片效果,實現(xiàn)圖片支持多點觸控,自由的進行縮放、平移的注意事項,感興趣的小伙伴們可以參考一下2016-02-02

