如何在一天中设置多个倒数计时器?

问题描述

我正在使用此类praytimes.org获取穆斯林的祈祷时间,即每天5次祈祷。值得庆幸的是,我能够做到这一点并在我的应用程序中显示它,但现在我想为所有五个数字设置一个倒数计时器,当第一个祈祷到达00:00:00时,它应该自动开始倒数第二个和第三个。 .etc,它应该自动重复。请帮助我

我的代码

                    val TimeId = TimezoneMapper.latLngToTimezonestring(location.latitude,location.longitude)

                    val gmt = TimeZone.getTimeZone(TimeId).getdisplayName(false,TimeZone.SHORT)

                    val z1 = gmt.substring(4)
                    val z = z1.replace(":",".")
                    val zo = z.todouble()
                    val latitude: Double = location.latitude
                    val longitude: Double = location.longitude

                    val locationPref = getSharedPreferences("location",Context.MODE_PRIVATE)
                    val editor = locationPref.edit()
                    //    editor.putFloat("lat",lat1.toFloat())
                    //   editor.putFloat("lng",lng.toFloat())
                    locationPref.edit().putDouble("latt1",latitude).apply()
                    locationPref.edit().putDouble("lngg2",longitude).apply()

                    editor.apply()

                    lat.text = "LAT:$latitude"
                    Long.text = "LONG:$longitude"
                    timeZone2.text = "TimeZone:$zo"


                    val timeZoneId = TimeZone.getAvailableIDs()
                    val prayTime = praytime()
                    prayTime.timeFormat = prayTime.time12 // getTime12 is protected
                    prayTime.calcmethod = prayTime.makkah // Makkah
                    prayTime.asrJuristic = prayTime.shafii // Shafii (standard)
                    prayTime.adjustHighLats = prayTime.angleBased
                    // my codes
                    prayTime.timeZone = prayTime.timeZone1
                    prayTime.setFajrAngle(18.5)

                    prayTime.computeMidDay(prayTime.dhuhrMinutes.todouble())
                    val offsets = intArrayOf(
                        0,0
                    ) // {Fajr,Sunrise,Dhuhr,Asr,Sunset,Maghrib,Isha}

                    prayTime.tune(offsets)
                    val cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId.toString()))
                    val Now = Date()
                    cal.time = Now



                    val times: ArrayList<String> =
                        prayTime.getPrayerTimes(
                            cal,latitude,longitude,zo
                        )
                    findViewById<TextView>(R.id.Fajr).text = times.get(0)
                    findViewById<TextView>(R.id.sabah).text = times.get(1)
                    findViewById<TextView>(R.id.dhuhr).text = times.get(2)
                    findViewById<TextView>(R.id.AzanTime).text = times.get(3)
                    findViewById<TextView>(R.id.maghreb).text = times.get(4)
                    findViewById<TextView>(R.id.Esha).text = times.get(6)

我尝试使用下面的代码来制作它,但是它不起作用

 val currentTime = Calendar.getInstance().time
                        val endDateDay = "6/09/2020 ${times[0]} "
                        val format1 = SimpleDateFormat("DD/MM/YY hh:mm",Locale.getDefault())
                        val endDate = format1.parse(endDateDay)

                        //milliseconds
                        var different = endDate.time - currentTime.time
                        countDownTimer = object : CountDownTimer(different,1000) {

                            override fun onTick(millisUntilFinished: Long) {
                                var diff = millisUntilFinished
                                val secondsInMilli: Long = 1000
                                val minutesInMilli = secondsInMilli * 60
                                val hoursInMilli = minutesInMilli * 60
                                val daysInMilli = hoursInMilli * 24

                                val elapsedDays = diff / daysInMilli
                                diff %= daysInMilli

                                val elapsedHours = diff / hoursInMilli
                                diff %= hoursInMilli

                                val elapsedMinutes = diff / minutesInMilli
                                diff %= minutesInMilli

                                val elapsedSeconds = diff / secondsInMilli

                                SalahCount.text = "$elapsedDays days $elapsedHours hs $elapsedMinutes min $elapsedSeconds sec"
                            }

                            override fun onFinish() {
                                SalahCount.text = "done!"
                            }
                        }.start()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)