android 时间选择器

android 时间选择器 (类似外卖跑腿下单)

在这里插入图片描述
github链接

打开弹框

  btnShow.setOnClickListener {
            if (timeDialog == null) {
                //30: 时间间隔  当前时间往后延迟30分钟
                //例:当前时间10:48 可选的时间段11:20往后
                timeDialog = TimeDialogFragment(30)
            } else {
                timeDialog = TimeDialogFragment(30)
            }
            timeDialog!!.show(supportFragmentManager, "")
        }

数据填充

   private fun initData() {
        dayList = StringHelper.getDay2()
        wheelDay!!.adapter = MyAdapter(dayList!!)
        val c = Calendar.getInstance()
        hourList =
            StringHelper.getHourTime(c.get(Calendar.HOUR_OF_DAY), timeNum, c.get(Calendar.MINUTE))

        hourAdapter = MyAdapter(hourList!!)
        wheelHour!!.adapter = hourAdapter

        wheelDay!!.setOnItemSelectedListener { index ->
            curDay = index

            wheelHour!!.currentItem = 0
            wheelMin!!.currentItem = 0
            if (index == 0) {//当天
                hourAdapter = null
                val currentHour = wheelHour!!.currentItem
                if (currentHour == 0) {
                    wheelMin!!.visibility = View.GONE
                } else {
                    wheelMin!!.visibility = View.VISIBLE
                }
                hourAdapter = MyAdapter(hourList!!)
                wheelHour!!.adapter = hourAdapter
            } else {//第二天
                val currHour = c.get(Calendar.HOUR_OF_DAY)
                //                    currHour = 23;
                val hour = timeNum / 60
                if (currHour + hour > 23) {//第二天需要动态修改
                    hourAdapter = null
                    wheelMin!!.visibility = View.VISIBLE
                    twoHourList = StringHelper.getTwoHourTime(currHour + hour - 24)
                    hourAdapter = MyAdapter(twoHourList!!)
                    wheelHour!!.adapter = hourAdapter
                    minAdapter = null
                    minList = StringHelper.getMin(false, timeNum, c.get(Calendar.MINUTE))
                    minAdapter = MyAdapter(minList!!)
                    wheelMin!!.adapter = minAdapter
                    wheelMin!!.visibility = View.VISIBLE
                } else {//第二天数据正常
                    hourAdapter = null
                    wheelMin!!.visibility = View.VISIBLE
                    twoHourList = StringHelper.getHourAll()
                    hourAdapter = MyAdapter(twoHourList!!)
                    wheelHour!!.adapter = hourAdapter
                    minAdapter = null
                    minList = StringHelper.getMin(true, 0, 0)
                    minAdapter = MyAdapter(minList!!)
                    wheelMin!!.adapter = minAdapter
                    wheelMin!!.visibility = View.VISIBLE
                }

            }
        }
        wheelHour!!.setOnItemSelectedListener { index ->
            if (curDay == 0) {//今天
                if (index == 0) {
                    wheelMin!!.visibility = View.GONE
                } else if (index == 1) {
                    minAdapter = null
                    minList = StringHelper.getMin(false, timeNum, c.get(Calendar.MINUTE))
                    minAdapter = MyAdapter(minList!!)
                    wheelMin!!.adapter = minAdapter
                    wheelMin!!.visibility = View.VISIBLE
                } else {
                    minAdapter = null
                    minList = StringHelper.getMin(true, 0, 0)
                    minAdapter = MyAdapter(minList!!)
                    wheelMin!!.adapter = minAdapter
                    wheelMin!!.visibility = View.VISIBLE
                }
            } else {//明天
                val currHour = c.get(Calendar.HOUR_OF_DAY)
                //                    currHour = 23;
                val hour = timeNum / 60
                if (currHour + hour > 23) {//第二天需要动态修改
                    if (index == 0) {
                        minAdapter = null
                        minList = StringHelper.getMin(false, timeNum, c.get(Calendar.MINUTE))
                        minAdapter = MyAdapter(minList!!)
                        wheelMin!!.adapter = minAdapter
                        wheelMin!!.visibility = View.VISIBLE
                    } else {
                        minAdapter = null
                        minList = StringHelper.getMin(true, 0, 0)
                        minAdapter = MyAdapter(minList!!)
                        wheelMin!!.adapter = minAdapter
                        wheelMin!!.visibility = View.VISIBLE
                    }

                } else {
                    minAdapter = null
                    minList = StringHelper.getMin(true, 0, 0)
                    minAdapter = MyAdapter(minList!!)
                    wheelMin!!.adapter = minAdapter
                    wheelMin!!.visibility = View.VISIBLE
                }

            }
        }
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值