源码简介
一款强大的时间选择控件
源码运行截图
代码片段:
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- final CalendarPickerView dialogView = (CalendarPickerView) getLayoutInflater()
- .inflate(R.layout.dialog, null, false);
- if (text.getText().toString().equals("")) {
- dialogView.init(new Date(), month.getTime())
- .withSelectedDate(new Date());
- } else {
- Date date = DateUtils.getDate(text.getText().toString(),
- "yyyy-MM-dd");
- dialogView.init(new Date(), month.getTime())
- .withSelectedDate(date);
- }
- new AlertDialog.Builder(MainActivity.this)
- .setTitle("时间选择控件")
- .setView(dialogView)
- .setNeutralButton("返回",
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(
- DialogInterface dialogInterface,
- int i) {
- dialogInterface.dismiss();
- }
- })
- .setPositiveButton("确定",
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(
- DialogInterface dialogInterface,
- int i) {
- long sd = dialogView.getSelectedDate()
- .getTime();
- Date dat = new Date(sd);
- GregorianCalendar gc = new GregorianCalendar();
- gc.setTime(dat);
- java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(
- "yyyy-MM-dd ");
- String sb = format.format(gc.getTime());
- text.setText(sb);
- dialogInterface.dismiss();
- }
- }).create().show();
- }