更新复选框prefefences最好的方法 [英] Best way to update checkbox prefefences
问题描述
我被编码为Android的时钟。对于它,我设置的更新画面1时间的函数每次一秒钟,因此我的程序会消耗大量的资源,而我的目标就是增加一个复选框,preference,消耗更少的资源,我可以。
I was coding a clock for android. For it, i set a function which updates screen 1 time each a second, so my program can consume a lot of resources, and my objective is to add a checkbox preference, consuming the less resources as I can.
然后,我的问题是:我看到了一些的方式与 onShared preferenceChangeListener
例如更新preferences ...这是消耗的方式系统资源少?我应该如何实现它向我的code?
Then, my question is: I have seen some ways to update preferences with onSharedPreferenceChangeListener
for example... Which is the way which consumes less system resources? How should I implement it to my code?
推荐答案
如果您使用的是 preferenceActivity
您可以实现开preferenceClickListener
上的复选框设置一个监听器,然后在你的上preferenceClick
方法,关键你的框中设置并做什么你需要用它做
if you are using a PreferenceActivity
you can implement the OnPreferenceClickListener
set a listener on the checkbox then in your onPreferenceClick
method with the key you set for the box and do what you need to do with it
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals("schedulestart")) {
showDialog(0);
} else if (preference.getKey().equals("schedulestop")) {
showDialog(1);
} else if (preference.getKey().equals("priority")) {
// Reset unread count when switching mailboxes. They might differ.
getPreferenceManager().getSharedPreferences().edit().putInt("unreadcount", 0).commit();
}
return true;
}
这篇关于更新复选框prefefences最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!