我如何捕获Android开发一个CheckBox preference的变化? [英] How do I capture changes of a CheckBoxPreference in android development?

查看:129
本文介绍了我如何捕获Android开发一个CheckBox preference的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何为Android做动态壁纸。我有它的工作,现在我想补充一对夫妇preferences。所以,我创建了一个preference活动,并遵循所有的例子我能找到。

I'm trying to learn how to do live wallpapers for android. I've got it working and now I want to add a couple preferences. So, I've created a preference activity and followed all the examples I could find.

我可以捕捉列表框preferences就好了,但是当一个复选框被改变永远不会被称为onShared preferenceChanged的方法。

I can capture ListBoxPreferences just fine, but the 'onSharedPreferenceChanged' method is never called when a checkbox has been changed.

是否有必须添加捕捉复选框的变化额外的code吗?是否有preferences做复选框的最佳实践方法是什么?

Is there extra code that has to be added for capturing checkbox changes? Is there a best practices way of doing check boxes in preferences?

我一直在敲我的头靠在这个问题了两天,任何帮助将不胜AP preciated!

I've been banging my head against this issue for two days, any help would be GREATLY appreciated!

谢谢!

推荐答案

@Josh - 好答案

@Josh - Good answer.

我想补充为完整起见是,你应该设定让您注册在preferenceActivity的onResume()方法的变化,并在注销的onPause()方法。

I'd like to add for the sake of completeness is that you should set things up so you register for changes in your PreferenceActivity's onResume() method and unregister in the onPause() method.

答案<一个href=\"http://stackoverflow.com/questions/531427/how-do-i-display-the-current-value-of-an-android-$p$pference-in-the-$p$pference-sum\">this问题拥有的股票的Andr​​oid示例程序采取code的良好样本。

The answer to this question has a good sample of code taken from on the the stock Android example programs.

另外,您也可以注册听众为每个在活动的onCreate(在preferences),并分别处理它们的事件。

Alternatively, you can also register listeners for each of the preferences in your activity's onCreate() and handle events on them separately .

这篇关于我如何捕获Android开发一个CheckBox preference的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆