按下一段时间后锁定按钮

发布于 2024-10-03 17:32:17 字数 281 浏览 1 评论 0原文

以下是场景:

用户打开应用程序,按下按钮并启动一些活动。按下按钮并执行活动后,我想禁用该按钮,直到本周开始。即使他们关闭应用程序并返回,它仍然应该被禁用,除非它已重置。

例如,如果他们在星期一按下该按钮,那么直到星期日中午 12:00 之前他们应该无法再次执行此操作。

无论他们在哪一天第一次按下按钮,他们都不应该能够再次按下,直到本周重新开始。

在 android 中执行此操作最简单的方法是什么?我是否应该让程序存储他们最初按下的日期和时间,然后计算每次打开应用程序时重置的时间?

Here is the scenario:

User opens app, they press a button and some activity launches. After the button is pressed and the activity is executed, I want to disable the button until the week starts over. Even if they close the app and come back, it should still be disabled unless it has reset.

For example, if they press the button on Monday, they should not be able to do it again until Sunday at 12:00 AM.

No matter what day they initially press the button, they should not be able to press again until the week starts over.

What would be the simplest way to do this in android? Should I have the program store the date and time they initially press, and then calculate the time until reset every time they open the app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔少女心 2024-10-10 17:32:17

我能为您想到的最简单的方法是将日期放入您的应用程序的数据库中。这样,当用户单击该按钮时,您将创建一个 Date 对象,将其设置为您想要的格式,并以相同的格式创建另一个 + 7 天。您将第二个日期放入数据库中,每次使用按钮启动活动时,您都会检查数据库并将当天的日期与数据库中的日期进行比较。这样,从数据库检索值后不进行任何计算,只是进行比较。最后,您只需设置按钮的图像及其可点击状态即可匹配测试结果。

The easiest way I could think of for you would be to put the dates in the database of your app. So that when the user clicks the button, you create a Date object, put it in the format you want and create another one + 7 days in the same format. You put the 2nd date in the database and every time you launch the activity with the button, you check the database and compare the date of the day with the one in the database. This way, no calculation done after retrieving the value from the DB, just comparison. You finally just have to set up the images of the button and its clickable states to match the results of the test.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文