码迷,mamicode.com
首页 > 移动开发 > 详细

Android --slidedatetimepicker时间控件应用

时间:2015-09-11 17:27:31      阅读:769      评论:0      收藏:0      [点我收藏+]

标签:

下载参考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());
        }
    };

 

Android --slidedatetimepicker时间控件应用

标签:

原文地址:http://www.cnblogs.com/bmbh/p/4801347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!