下载参考SlideDateTimePicker时间选择器

1、创建

        beginTimeTxt=(EditText)findViewById(R.id.search_begintime_edittext);
        endTimeTxt=(EditText)findViewById(R.id.search_endtime_edittext);

        beginTimeTxt.setOnClickListener(new MySearchClickListener());

        beginTimeTxt.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                beginTimeTxt.setInputType(InputType.TYPE_NULL); //关闭软键盘
                return false;
            }
        });
        endTimeTxt.setOnClickListener(new MySearchClickListener());

        endTimeTxt.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                endTimeTxt.setInputType(InputType.TYPE_NULL); //关闭软键盘
                return false;
            }
        });

2、监听事件

    class MySearchClickListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                //开始时间
                case R.id.search_begintime_edittext:
                    new SlideDateTimePicker.Builder(getSupportFragmentManager())
                            .setListener(MyBeginDateTimelistener)
                            .setInitialDate(new Date())
                                    //.setMinDate(minDate)
                                    //.setMaxDate(maxDate)
                                    //.setIs24HourTime(true)
                                    //.setTheme(SlideDateTimePicker.HOLO_DARK)
                                    //.setIndicatorColor(Color.parseColor("#990000"))
                            .build()
                            .show();
                    break;
                //结束时间
                case R.id.search_endtime_edittext:
                    new SlideDateTimePicker.Builder(getSupportFragmentManager())
                            .setListener(MyEndDateTimelistener)
                            .setInitialDate(new Date())
                                    //.setMinDate(minDate)
                                    //.setMaxDate(maxDate)
                                    //.setIs24HourTime(true)
                                    //.setTheme(SlideDateTimePicker.HOLO_DARK)
                                    //.setIndicatorColor(Color.parseColor("#990000"))
                            .build()
                            .show();
                    break;
            }
        }
    }

    SlideDateTimeListener MyBeginDateTimelistener = new SlideDateTimeListener() {
        @Override
        public void onDateTimeSet(Date date){
            beginTimeTxt.setText(mTimeFormat.format(date).toString());
        }
    };

    SlideDateTimeListener MyEndDateTimelistener = new SlideDateTimeListener() {
        @Override
        public void onDateTimeSet(Date date){
            endTimeTxt.setText(mTimeFormat.format(date).toString());
        }
    };
04-21 03:57