Android仿IOS时间_Android仿IOS弹出提示框
2014-11-23 16:29:44 By: shinyuu
本例子实现了Android移动程序弹出像IOS一样的弹出框(IOSDialog)、由于项目中需要用仿ios的弹出提示选择日期和地区以及IOS列表选择等、又一次重新封装、实现了像IOS一样选择日期和地区、效果还是不错的、比起我上一次分享的一个日期选择控件漂亮多了、(安卓仿iphone日期时间选择控件http://dwtedx.com/itshare_213.html)希望大家喜欢、先来看看程序运行的效果吧
下面进行一下简单的代码分析
onCreate方法代码
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); 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) ""); }
initView方法代码
private void initView() { btn1 = (Button) findViewById(R.id.btn1); btn1.setOnClickListener(this); btn2 = (Button) findViewById(R.id.btn2); btn2.setOnClickListener(this); btn3 = (Button) findViewById(R.id.btn3); btn3.setOnClickListener(this); btn4 = (Button) findViewById(R.id.btn4); btn4.setOnClickListener(this); btn5 = (Button) findViewById(R.id.btn5); btn5.setOnClickListener(this); }
时间调用方法
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); 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); wheelMain.initDateTimePicker(year, month, day); 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();
最后给大家贴上百度云盘的源代码下载链接、希望对大家有帮助
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1fHOoI 密码: 81w0
若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力
想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)
或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)
如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教
为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)
感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛