Android - 简单的视图刷新
我不认为我的未来在于 Android 开发,因为我一直在最简单的事情上失败......
我有一个带有标签“Game Slot 1”的按钮。当用户单击它时,我成功地引导他们完成一些创建新角色的活动。我将游戏名称保存在 SQLite 数据库中,下次启动应用程序时,我可以很高兴地将“游戏插槽 1”动态更改为数据库中该插槽游戏的名称。完美的。
但是,当我通过后退按钮返回该活动或在所有后续活动中调用 finish() 时,我到底如何让它以相同的方式更新视图呢?
我确信这与 onResume() 有关,也许与 invalidate() 有关,但我似乎找不到示例。
只是为了在 Resume() 上刷新一些 UI 元素而使 invalidate 过大吗?
无论如何,即使是这样,你到底如何使用它?
有更好的办法吗?
预先非常感谢您提供的任何帮助...只是尽量不要嘲笑这可能是多么简单! :)
干杯, 詹姆斯
I don't think my future lies in Android development, as I am consistently failing at the simplest things...
I've got a button with the label "Game Slot 1". When the user clicks it, I succesfully take them through a couple of activities in which they create a new character. I save the game name in an SQLite database, and the next time I launch my app, I can quite happily dynamically change "Game Slot 1" to the name of that slot's game from the database. Perfect.
But how on earth do I get it to update the view in the same manner when I return to that activity via the back button, or having called finish() on all the subsequent activities?
I'm sure it's something to do with onResume(), and maybe invalidate(), but I just can't seem to find an example.
Is invalidate overkill just to refresh a few UI elements onResume()?
How the heck do you use it, anyway, even if it is?
Is there a better way?
Many thanks in advance for any help offered...just try not to laugh at how simple this probably is! :)
Cheers,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是您可以在 onResume 中执行的操作,只需查询数据库并在感兴趣的元素上调用 setText 即可。您不需要显式调用 invalidate。
That sounds like something you could do in onResume, just query the database and call setText on the element of interest. You should not need to explicitly call invalidate.