Android Studio 进度条的视觉问题

发布于 2025-01-10 09:18:13 字数 484 浏览 3 评论 0原文

我添加了一个选项,可以在活动编号 1 中单击它,以保存共享首选项,并且它应该重新启动活动 nr 2 中的进度条进度,但问题是,即使我转到活动 nr 2 并调用 setProgress(0) 并且 getProgress 返回0,进度条上的进度仍然存在,并且只有在重新启动应用程序后进度条才会更新。我应该做什么来修复它?

在活动 nr 1 中单击的代码

sharedPreferences.edit().putBoolean("restarted", true).apply();

在活动 nr 2 中设置进度条的代码

if(sharedPreferences.getBoolean("restarted", false)) {
    progress.setProgress(0);
    sharedPreferences.edit().putBoolean("restarted", false).apply();
}

I added an option to click on it in activity number 1 that saves sharedpreferences, and it should restart progressbar progress in activity nr 2, but the problem is that even when I go to activity nr 2 and setProgress(0) is called and getProgress returns 0, progress on progressbar is still there, and only after restarting app progressbar updates. What should I do to repair it?

Code on click in activity nr 1

sharedPreferences.edit().putBoolean("restarted", true).apply();

Code in activity nr 2 to set progressbar

if(sharedPreferences.getBoolean("restarted", false)) {
    progress.setProgress(0);
    sharedPreferences.edit().putBoolean("restarted", false).apply();
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文