Android仿IOS时间_Android仿IOS弹出提示框
程序员文章站
2022-03-01 14:48:50
...
本例子实现了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