简体   繁体   English

我如何使用SharedPref。 在ArrayAdapter类文件中?

[英]How do I use a SharedPref. in an ArrayAdapter class file?

I have a custom Array Adapter to display a list of items, in this case, highscores. 我有一个自定义数组适配器来显示项目列表,在本例中是高分。 The system sort of mimics a folder scheme; 系统类型模仿文件夹方案; one clicks a folder named "Game 1" and it goes to a new list with the top 10 scorers. 单击一个名为“Game 1”的文件夹,它将进入一个包含前10名得分者的新列表。 When you take a test, it changes a sharedpreferences called isPlayed, and if isPlayed is 1, the image for that Game, Game 1, is green, otherwise, if you never play Game 1, isPlayed is never 0, and therefor the image on the highscore list of games is red. 当您进行测试时,它会更改名为isPlayed的共享偏好,如果isPlayed为1,则该游戏的图像(游戏1)为绿色,否则,如果您从未玩过游戏1,则isPlayed永远不会为0,因此图像上高分榜的比赛是红色的。 But, SharedPreferences seems to be unknown in a class that extends ArrayAdapter. 但是,在扩展ArrayAdapter的类中,SharedPreferences似乎是未知的。 How can I use data from sharedpreferences here? 我如何在这里使用来自共享偏好的数据? Post a question if you need more info. 如果您需要更多信息,请发帖提问。

PreferenceManager.getDefaultSharedPreferences(YourActivity.this)

或者,而不是YourActivity.this您可以使用应用程序中的任何Context ,例如您的应用程序上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM