gpt4 book ai didi

android - 要遵循的编程范式

转载 作者:行者123 更新时间:2023-11-29 21:53:31 24 4
gpt4 key购买 nike

我目前正在开发一个应用程序,在该应用程序中,用户会看到一系列列表,单击每个列表,用户会根据他的选择被带到另一个列表。现在为了记住用户在每个屏幕上做了什么,我在我的共享首选项中插入了一系列字符串。事实证明,由于我的应用程序有大约 7 8 个选择屏幕,我的整个代码只是与共享首选项中的读写键纠缠在一起。

air_conditioning = Session.getBoolean(SELL_AIR_CONDITIONINING) ? "1" : "0";
power_steering = Session.getBoolean(SELL_POWER_STEERING) ? "1" : "0";
power_locks = Session.getBoolean(SELL_POWER_LOCKS) ? "1" : "0";
power_mirrors = Session.getBoolean(SELL_POWER_MIRROR) ? "1" : "0";
keyless_entry = Session.getBoolean(SELL_KEYLESS_ENTRY) ? "1" : "0";
cruise_control = Session.getBoolean(SELL_CRUISE_CONTROL) ? "1" : "0";
navigation_system = Session.getBoolean(SELL_NAVIGATION_SYSTEM) ? "1" : "0";
abs = Session.getBoolean(SELL_ABS) ? "1" : "0";
am_fm_radio = Session.getBoolean(SELL_FM_AM_RADIO) ? "1" : "0";
cassette_player = Session.getBoolean(SELL_CASSETE_PLAYER) ? "1" : "0";
cd_player = Session.getBoolean(SELL_CD_PLAYER) ? "1" : "0";
sun_roof = Session.getBoolean(SELL_SUN_ROOF) ? "1" : "0";
alloy_rims = Session.getBoolean(SELL_ALLOW_RIMS) ? "1" : "0";

所以这基本上就是我的全部代码,它看起来很丑,容易出错,而且不太可维护。在这种情况下,我一直在寻找任何适合我的解决方案。

亲切的问候

最佳答案

不要使用 SharedPreferences。使用 Intent s 并通过 Bundle 传递状态.

关于android - 要遵循的编程范式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13832740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com