本文实例为大家分享了AndroID仿iPhone时间选择器的具体代码,供大家参考,具体内容如下
先看效果图
如何使用
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("取消",int which) { } }).show(); } }); } }
源码下载:仿iPhone日期时间选择器
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的Android仿iPhone日期时间选择器详解全部内容,希望文章能够帮你解决Android仿iPhone日期时间选择器详解所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)