我正在尝试CountDownTimer在 Android 应用程序活动的 .java 中实现 a 。这CountDownTimer需要能够从用户选择指定的几个不同的预设时间倒计时,我已经通过使用sharedPreferences().
为了连接sharedPreferences和CountDownTimer的时间,以下是我尝试过的两种不起作用的方法:
1)getInt从 开始sharedPreferences,然后定义一个字符串数组,并用数组中的一个值替换long milliseconds( ) ,然后使用获得的字符串。CountDownTimerlongarray[int]valueof()
2) 通过使用{if(sharedPreferences == 123) {int timing = 5000;}}, 但这会失败,因为大括号包含的值int timing无法CountDownTimer读取它,因为它位于包含 . 的那对大括号之外if。值得一提的是,无法将其CountDownTimer移入大括号。
很简单,我正在寻找可编辑的CountDownTimer. 虽然我不是在 Stackoverflow 上要求完整的教程,但如果你能指出我正确的方向,那就太好了。